Make export-name RegExp more strict (#642)
This commit is contained in:
Родитель
8663087ad1
Коммит
2f9fa6883f
|
@ -157,7 +157,7 @@ export class ExportNameWalker extends Lint.RuleWalker {
|
|||
|
||||
private validateExport(exportedName: string, node: ts.Node): void {
|
||||
const flags = Rule.getIgnoreCase(this.getOptions()) ? 'i' : '';
|
||||
const regex: RegExp = new RegExp(exportedName + '..*', flags); // filename must be exported name plus any extension
|
||||
const regex: RegExp = new RegExp(`^${exportedName}\\..+`, flags); // filename must be exported name plus any extension
|
||||
const fileName = Utils.fileBasename(this.getSourceFile().fileName);
|
||||
if (!regex.test(fileName)) {
|
||||
if (!this.isSuppressed(exportedName)) {
|
||||
|
|
|
@ -257,7 +257,7 @@ describe('exportNameRule', (): void => {
|
|||
{
|
||||
failure:
|
||||
'The exported module or identifier name must match the file name. ' +
|
||||
'Found: ExportNameRuleFailingTestInput2.tsx and ThisIsNotTheNameOfTheFile',
|
||||
'Found: ExportNameRuleFailingTestInput2.tsx and ExportNameRuleFailingTestInput',
|
||||
name: 'test-data/ExportName/ExportNameRuleFailingTestInput2.tsx',
|
||||
ruleName: 'export-name',
|
||||
startPosition: { character: 10, line: 2 }
|
||||
|
@ -265,6 +265,20 @@ describe('exportNameRule', (): void => {
|
|||
]);
|
||||
});
|
||||
|
||||
it('for prefixed name', (): void => {
|
||||
const inputFile: string = 'test-data/ExportName/PrefixedExpectedClassName.ts';
|
||||
TestHelper.assertViolations(ruleName, inputFile, [
|
||||
{
|
||||
failure:
|
||||
'The exported module or identifier name must match the file name. ' +
|
||||
'Found: PrefixedExpectedClassName.ts and ExpectedClassName',
|
||||
name: 'test-data/ExportName/PrefixedExpectedClassName.ts',
|
||||
ruleName: 'export-name',
|
||||
startPosition: { character: 10, line: 2 }
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it('for conflicting name in namespace', (): void => {
|
||||
const inputScript: string = `
|
||||
namespace com.example {
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
class ThisIsNotTheNameOfTheFile {}
|
||||
export = ThisIsNotTheNameOfTheFile; // does not match filename
|
||||
class ExportNameRuleFailingTestInput {}
|
||||
export = ExportNameRuleFailingTestInput; // does not match filename
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
class ExportNameRulePassingTestInput {}
|
||||
export = ExportNameRulePassingTestInput; // matches filename
|
||||
class ExportNameRulePassingTestInput2 {}
|
||||
export = ExportNameRulePassingTestInput2; // matches filename
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
class ExpectedClassName {}
|
||||
export = ExpectedClassName; // doesn't match file name with prefix
|
|
@ -60,7 +60,7 @@
|
|||
"chai-prefer-contains-to-index-of": true,
|
||||
"chai-vague-errors": true,
|
||||
"encoding": true,
|
||||
"export-name": true,
|
||||
"export-name": [true, { "allow": ["^Rule$"] }],
|
||||
"function-name": true,
|
||||
"import-name": true,
|
||||
"informative-docs": true,
|
||||
|
|
Загрузка…
Ссылка в новой задаче