-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
130 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@infinum/eslint-plugin": major | ||
--- | ||
|
||
Added `eslint-plugin-typescript-enum` dependency and rules to React config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { getReactTester } from './utils'; | ||
|
||
const ruleName = 'typescript-enum/no-const-enum'; | ||
|
||
const { test, validate } = getReactTester(ruleName, { parser: '@typescript-eslint/parser' }); | ||
|
||
test('should warn for const enums', () => | ||
validate( | ||
` | ||
const enum Foo { | ||
Bar = "Bar", | ||
Baz = "Baz", | ||
} | ||
`, | ||
[], | ||
[ | ||
'Unexpected `const` enum, use regular enum instead. As a side note, in modern TypeScript, you may not need an enum when an object with `as const` could suffice.', | ||
] | ||
)); | ||
|
||
test('should not warn for union types', () => | ||
validate( | ||
` | ||
type Foo = "Bar" | "Baz"; | ||
`, | ||
[], | ||
[] | ||
)); | ||
|
||
test.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { getReactTester } from './utils'; | ||
|
||
const ruleName = 'typescript-enum/no-enum'; | ||
|
||
const { test, validate } = getReactTester(ruleName, { parser: '@typescript-eslint/parser' }); | ||
|
||
test('should warn for enums without specified values', () => | ||
validate( | ||
` | ||
enum Foo { | ||
Bar, | ||
Baz | ||
} | ||
`, | ||
[], | ||
['In modern TypeScript, you may not need an enum when an object with `as const` could suffice.'] | ||
)); | ||
|
||
test('should warn for enums with specified values', () => | ||
validate( | ||
` | ||
enum Foo { | ||
Bar = 'Bar', | ||
Baz = 'Baz' | ||
} | ||
enum Foo { | ||
Bar = "BAR", | ||
Baz = "BAZ", | ||
} | ||
`, | ||
[], | ||
[ | ||
'In modern TypeScript, you may not need an enum when an object with `as const` could suffice.', | ||
'In modern TypeScript, you may not need an enum when an object with `as const` could suffice.', | ||
] | ||
)); | ||
|
||
test('should not warn for consts', () => | ||
validate( | ||
` | ||
const Foo = { | ||
Bar: 0, | ||
Baz: 1, | ||
} as const; | ||
type Foo = "Bar" | "Baz"; | ||
const Foo = { | ||
Bar: "BAR", | ||
Baz: "BAZ", | ||
} as const; | ||
`, | ||
[], | ||
[] | ||
)); | ||
|
||
test.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
import { TSESLint } from '@typescript-eslint/utils'; | ||
import eslintConfig from '../../../src/configs/react'; | ||
import { getTester } from '../../utils'; | ||
|
||
export const getReactTester = (ruleName: string): ReturnType<typeof getTester> => { | ||
export const getReactTester = ( | ||
ruleName: string, | ||
configOverride: TSESLint.ESLint.ESLintOptions['baseConfig'] = {} | ||
): ReturnType<typeof getTester> => { | ||
return getTester({ | ||
filePath: __filename, | ||
eslintConfig, | ||
eslintConfig: { | ||
...eslintConfig, | ||
...configOverride, | ||
}, | ||
ruleName: ruleName, | ||
}); | ||
}; |