-
-
Notifications
You must be signed in to change notification settings - Fork 478
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
1 parent
504de83
commit 2bf0c8d
Showing
4 changed files
with
61 additions
and
0 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
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
25 changes: 25 additions & 0 deletions
25
packages/eslint-plugin-antfu/src/rules/no-const-enum.test.ts
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,25 @@ | ||
import { RuleTester } from '@typescript-eslint/utils/dist/ts-eslint' | ||
import { it } from 'vitest' | ||
import rule, { RULE_NAME } from './no-const-enum' | ||
|
||
const valids = [ | ||
'enum E {}', | ||
] | ||
|
||
const invalids = [ | ||
'const enum E {}', | ||
] | ||
|
||
it('runs', () => { | ||
const ruleTester: RuleTester = new RuleTester({ | ||
parser: require.resolve('@typescript-eslint/parser'), | ||
}) | ||
|
||
ruleTester.run(RULE_NAME, rule, { | ||
valid: valids, | ||
invalid: invalids.map(i => ({ | ||
code: i, | ||
errors: [{ messageId: 'noConstEnum' }], | ||
})), | ||
}) | ||
}) |
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,33 @@ | ||
import { createEslintRule } from '../utils' | ||
|
||
export const RULE_NAME = 'no-const-enum' | ||
export type MessageIds = 'noConstEnum' | ||
export type Options = [] | ||
|
||
export default createEslintRule<Options, MessageIds>({ | ||
name: RULE_NAME, | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
description: 'Disallow using `const enum` expression', | ||
recommended: 'error', | ||
}, | ||
schema: [], | ||
messages: { | ||
noConstEnum: 'Do not use `const enum` expression', | ||
}, | ||
}, | ||
defaultOptions: [], | ||
create: (context) => { | ||
return { | ||
TSEnumDeclaration: (node) => { | ||
if (node.const) { | ||
context.report({ | ||
node, | ||
messageId: 'noConstEnum', | ||
}) | ||
} | ||
}, | ||
} | ||
}, | ||
}) |