refactor: change error message (#29594)

Removes usage of whitelist from error messages, comments and test descriptions in ts_api_guardian

Related to #28539

PR Close #29594
This commit is contained in:
Ben Lesh 2019-03-29 11:20:17 -07:00 committed by Jason Aden
parent d11b0c0c41
commit 1c07061246
3 changed files with 25 additions and 21 deletions

View File

@ -176,7 +176,7 @@ Options:
--useAngularTagRules <boolean> Whether the Angular specific tag rules should be used. --useAngularTagRules <boolean> Whether the Angular specific tag rules should be used.
--stripExportPattern <regexp> Do not output exports matching the pattern --stripExportPattern <regexp> Do not output exports matching the pattern
--allowModuleIdentifiers <identifier> --allowModuleIdentifiers <identifier>
Whitelist identifier for "* as foo" imports`); Allow identifier for "* as foo" imports`);
process.exit(error ? 1 : 0); process.exit(error ? 1 : 0);
} }

View File

@ -38,14 +38,14 @@ export interface SerializationOptions {
*/ */
stripExportPattern?: RegExp|RegExp[]; stripExportPattern?: RegExp|RegExp[];
/** /**
* Whitelists these identifiers as modules in the output. For example, * Allows these identifiers as modules in the output. For example,
* ``` * ```
* import * as angular from './angularjs'; * import * as angular from './angularjs';
* *
* export class Foo extends angular.Bar {} * export class Foo extends angular.Bar {}
* ``` * ```
* will produce `export class Foo extends angular.Bar {}` and requires * will produce `export class Foo extends angular.Bar {}` and requires explicitly allowing
* whitelisting angular. * `angular` as a module identifier.
*/ */
allowModuleIdentifiers?: string[]; allowModuleIdentifiers?: string[];
@ -242,7 +242,7 @@ class ResolvedDeclarationEmitter {
message: createErrorMessage( message: createErrorMessage(
firstQualifier, firstQualifier,
`Module identifier "${firstQualifier.text}" is not allowed. Remove it ` + `Module identifier "${firstQualifier.text}" is not allowed. Remove it ` +
`from source or whitelist it via --allowModuleIdentifiers.`) `from source or allow it via --allowModuleIdentifiers.`)
}); });
} }
} }

View File

@ -357,28 +357,32 @@ describe('unit test', () => {
check({'file.d.ts': input}, expected, {stripExportPattern: /^__.*/}); check({'file.d.ts': input}, expected, {stripExportPattern: /^__.*/});
}); });
it('should throw on using non-whitelisted module imports in expression position', () => { it('should throw on using module imports in expression position that were not explicitly allowed',
() => {
const input = ` const input = `
import * as foo from './foo'; import * as foo from './foo';
export declare class A extends foo.A { export declare class A extends foo.A {
} }
`; `;
checkThrows( checkThrows(
{'file.d.ts': input}, 'file.d.ts(2,32): error: Module identifier "foo" is not allowed. ' + {'file.d.ts': input},
'Remove it from source or whitelist it via --allowModuleIdentifiers.'); 'file.d.ts(2,32): error: Module identifier "foo" is not allowed. ' +
'Remove it from source or allow it via --allowModuleIdentifiers.');
}); });
it('should throw on using non-whitelisted module imports in type position', () => { it('should throw on using module imports in type position that were not explicitly allowed',
() => {
const input = ` const input = `
import * as foo from './foo'; import * as foo from './foo';
export type A = foo.A; export type A = foo.A;
`; `;
checkThrows( checkThrows(
{'file.d.ts': input}, 'file.d.ts(2,17): error: Module identifier "foo" is not allowed. ' + {'file.d.ts': input},
'Remove it from source or whitelist it via --allowModuleIdentifiers.'); 'file.d.ts(2,17): error: Module identifier "foo" is not allowed. ' +
'Remove it from source or allow it via --allowModuleIdentifiers.');
}); });
it('should not throw on using whitelisted module imports', () => { it('should not throw on using explicitly allowed module imports', () => {
const input = ` const input = `
import * as foo from './foo'; import * as foo from './foo';
export declare class A extends foo.A { export declare class A extends foo.A {
@ -391,7 +395,7 @@ describe('unit test', () => {
check({'file.d.ts': input}, expected, {allowModuleIdentifiers: ['foo']}); check({'file.d.ts': input}, expected, {allowModuleIdentifiers: ['foo']});
}); });
it('should not throw if non-whitelisted module imports are not written', () => { it('should not throw if module imports, that were not explicitly allowed, are not used', () => {
const input = ` const input = `
import * as foo from './foo'; import * as foo from './foo';
export declare class A { export declare class A {