feat(ts): ban const enum
(#201)
This commit is contained in:
parent
504de8392a
commit
2bf0c8d727
@ -159,6 +159,7 @@ module.exports = {
|
||||
'antfu/generic-spacing': 'error',
|
||||
'antfu/no-cjs-exports': 'error',
|
||||
'antfu/no-ts-export-equal': 'error',
|
||||
'antfu/no-const-enum': 'error',
|
||||
|
||||
// off
|
||||
'@typescript-eslint/consistent-indexed-object-style': 'off',
|
||||
|
@ -5,6 +5,7 @@ import preferInlineTypeImport from './rules/prefer-inline-type-import'
|
||||
import topLevelFunction from './rules/top-level-function'
|
||||
import noTsExportEqual from './rules/no-ts-export-equal'
|
||||
import noCjsExports from './rules/no-cjs-exports'
|
||||
import noConstEnum from './rules/no-const-enum'
|
||||
|
||||
export default {
|
||||
rules: {
|
||||
@ -15,5 +16,6 @@ export default {
|
||||
'top-level-function': topLevelFunction,
|
||||
'no-cjs-exports': noCjsExports,
|
||||
'no-ts-export-equal': noTsExportEqual,
|
||||
'no-const-enum': noConstEnum,
|
||||
},
|
||||
}
|
||||
|
25
packages/eslint-plugin-antfu/src/rules/no-const-enum.test.ts
Normal file
25
packages/eslint-plugin-antfu/src/rules/no-const-enum.test.ts
Normal file
@ -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' }],
|
||||
})),
|
||||
})
|
||||
})
|
33
packages/eslint-plugin-antfu/src/rules/no-const-enum.ts
Normal file
33
packages/eslint-plugin-antfu/src/rules/no-const-enum.ts
Normal file
@ -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',
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
Loading…
Reference in New Issue
Block a user