File tree Expand file tree Collapse file tree 4 files changed +61
-0
lines changed
Expand file tree Collapse file tree 4 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,7 @@ module.exports = {
159159 'antfu/generic-spacing' : 'error' ,
160160 'antfu/no-cjs-exports' : 'error' ,
161161 'antfu/no-ts-export-equal' : 'error' ,
162+ 'antfu/no-const-enum' : 'error' ,
162163
163164 // off
164165 '@typescript-eslint/consistent-indexed-object-style' : 'off' ,
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import preferInlineTypeImport from './rules/prefer-inline-type-import'
55import topLevelFunction from './rules/top-level-function'
66import noTsExportEqual from './rules/no-ts-export-equal'
77import noCjsExports from './rules/no-cjs-exports'
8+ import noConstEnum from './rules/no-const-enum'
89
910export default {
1011 rules : {
@@ -15,5 +16,6 @@ export default {
1516 'top-level-function' : topLevelFunction ,
1617 'no-cjs-exports' : noCjsExports ,
1718 'no-ts-export-equal' : noTsExportEqual ,
19+ 'no-const-enum' : noConstEnum ,
1820 } ,
1921}
Original file line number Diff line number Diff line change 1+ import { RuleTester } from '@typescript-eslint/utils/dist/ts-eslint'
2+ import { it } from 'vitest'
3+ import rule , { RULE_NAME } from './no-const-enum'
4+
5+ const valids = [
6+ 'enum E {}' ,
7+ ]
8+
9+ const invalids = [
10+ 'const enum E {}' ,
11+ ]
12+
13+ it ( 'runs' , ( ) => {
14+ const ruleTester : RuleTester = new RuleTester ( {
15+ parser : require . resolve ( '@typescript-eslint/parser' ) ,
16+ } )
17+
18+ ruleTester . run ( RULE_NAME , rule , {
19+ valid : valids ,
20+ invalid : invalids . map ( i => ( {
21+ code : i ,
22+ errors : [ { messageId : 'noConstEnum' } ] ,
23+ } ) ) ,
24+ } )
25+ } )
Original file line number Diff line number Diff line change 1+ import { createEslintRule } from '../utils'
2+
3+ export const RULE_NAME = 'no-const-enum'
4+ export type MessageIds = 'noConstEnum'
5+ export type Options = [ ]
6+
7+ export default createEslintRule < Options , MessageIds > ( {
8+ name : RULE_NAME ,
9+ meta : {
10+ type : 'problem' ,
11+ docs : {
12+ description : 'Disallow using `const enum` expression' ,
13+ recommended : 'error' ,
14+ } ,
15+ schema : [ ] ,
16+ messages : {
17+ noConstEnum : 'Do not use `const enum` expression' ,
18+ } ,
19+ } ,
20+ defaultOptions : [ ] ,
21+ create : ( context ) => {
22+ return {
23+ TSEnumDeclaration : ( node ) => {
24+ if ( node . const ) {
25+ context . report ( {
26+ node,
27+ messageId : 'noConstEnum' ,
28+ } )
29+ }
30+ } ,
31+ }
32+ } ,
33+ } )
You can’t perform that action at this time.
0 commit comments