Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Add Exclusion Names for Rule file-name-casing (#4204)
Browse files Browse the repository at this point in the history
* Add Exclusion Names for Rule file-name-casing

- Add exclusion option for one or more files
- Add test files

* Rename method for checking file exemption

* Fix lint errors

* address review comments

* Post-merge: remove some now unnecessary tests

* Ah, corrected new test cases to fail as needed

* Lint complaint
  • Loading branch information
rwaskiewicz authored and Josh Goldberg committed Jun 16, 2019
1 parent 5d135e8 commit 9d6d49a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/rules/fileNameCasingRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { isCamelCased, isKebabCased, isPascalCased, isSnakeCased } from "../util
enum Casing {
CamelCase = "camel-case",
PascalCase = "pascal-case",
Ignored = "ignored",
KebabCase = "kebab-case",
SnakeCase = "snake-case",
}
Expand All @@ -49,6 +50,8 @@ function isCorrectCasing(fileName: string, casing: Casing): boolean {
return isCamelCased(fileName);
case Casing.PascalCase:
return isPascalCased(fileName);
case Casing.Ignored:
return true;
case Casing.KebabCase:
return isKebabCased(fileName);
case Casing.SnakeCase:
Expand Down Expand Up @@ -142,6 +145,7 @@ export class Rule extends Lint.Rules.AbstractRule {
* \`${Casing.PascalCase}\`: File names must be Pascal-cased: \`FileName.ts\`.
* \`${Casing.KebabCase}\`: File names must be kebab-cased: \`file-name.ts\`.
* \`${Casing.SnakeCase}\`: File names must be snake-cased: \`file_name.ts\`.
* \`${Casing.Ignored}\`: File names are ignored _(useful for the object configuration)_.
Or an object, where the key represents a regular expression that
matches the file name, and the value is the file name rule from
Expand Down Expand Up @@ -193,6 +197,13 @@ export class Rule extends Lint.Rules.AbstractRule {
".*": Casing.CamelCase,
},
],
[
true,
{
".ts": Casing.Ignored,
".tsx": Casing.PascalCase,
},
],
],
hasFix: false,
type: "style",
Expand All @@ -214,6 +225,8 @@ export class Rule extends Lint.Rules.AbstractRule {
return "camelCase";
case Casing.PascalCase:
return "PascalCase";
case Casing.Ignored:
return "ignored";
case Casing.KebabCase:
return "kebab-case";
case Casing.SnakeCase:
Expand Down
2 changes: 2 additions & 0 deletions test/rules/file-name-casing/ignore/complaint.tsx.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

~nil [File name must be PascalCase]
Empty file.
8 changes: 8 additions & 0 deletions test/rules/file-name-casing/ignore/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"rules": {
"file-name-casing": [true, {
".ts": "ignore",
".tsx": "pascal-case"
}]
}
}

0 comments on commit 9d6d49a

Please sign in to comment.