Last active
December 17, 2021 02:15
-
-
Save kestrelnova/8dd330e361a63d157d7951c883c6b974 to your computer and use it in GitHub Desktop.
@typescript-eslint/naming-convention testing with XO
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
module.exports = { | |
rules: { | |
'@typescript-eslint/naming-convention': [ | |
'error', | |
{ | |
// selector: ['variableLike', 'memberLike', 'property', 'method'], | |
// Note: Leaving out `parameter` and `typeProperty` because of the mentioned known issues. | |
// Note: We are intentionally leaving out `enumMember` as it's usually pascal-case or upper-snake-case. | |
selector: ['variable', 'function', 'classProperty', 'objectLiteralProperty', 'parameterProperty', 'classMethod', 'objectLiteralMethod', 'typeMethod', 'accessor'], | |
format: [ | |
'strictCamelCase' | |
], | |
// We allow double underscope because of GraphQL type names and some React names. | |
leadingUnderscore: 'allowSingleOrDouble', | |
trailingUnderscore: 'allow' | |
}, | |
{ | |
selector: 'typeLike', | |
format: [ | |
'StrictPascalCase' | |
] | |
}, | |
{ | |
selector: 'variable', | |
types: [ | |
'boolean' | |
], | |
format: [ | |
'StrictPascalCase' | |
], | |
prefix: [ | |
'is', | |
'has', | |
'can', | |
'should', | |
'will', | |
'did' | |
] | |
}, | |
// Allow UPPER_CASE in global constants. | |
{ | |
selector: 'variable', | |
modifiers: ['const', 'global'], | |
format: ['strictCamelCase', 'UPPER_CASE'] | |
}, | |
{ | |
selector: 'variable', | |
types: ['boolean'], | |
modifiers: ['const', 'global'], | |
format: ['UPPER_CASE'], | |
prefix: ['IS_', 'HAS_', 'CAN_', 'SHOULD_', 'WILL_', 'DID_'], | |
filter: '[A-Z]{2,}' | |
}, | |
{ | |
// Interface name should not be prefixed with `I`. | |
selector: 'interface', | |
filter: /^(?!I)[A-Z]/.source, | |
format: [ | |
'StrictPascalCase' | |
] | |
}, | |
{ | |
// Type parameter name should either be `T` or a descriptive name. | |
selector: 'typeParameter', | |
filter: /^T$|^[A-Z][a-zA-Z]+$/.source, | |
format: [ | |
'StrictPascalCase' | |
] | |
}, | |
// Allow these in non-camel-case when quoted. | |
{ | |
selector: [ | |
'classProperty', | |
'objectLiteralProperty' | |
], | |
format: null, | |
modifiers: [ | |
'requiresQuotes' | |
] | |
} | |
] | |
} | |
} |
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
// Allowed | |
const globalConst = 'a string'; | |
const isGlobalBoolean = true; | |
let isBoolean = true; | |
const GLOBAL_CONST = 'a string'; | |
const IS_GLOBAL_BOOLEAN = true; | |
const quotedProperties = { | |
'Has-Dash': 13, | |
'has.dot': 13, | |
'has SPACE': 13, | |
}; | |
// Not allowed | |
const global_const = 'a string'; | |
let nonconstantboolean = true; | |
const isglobalboolean = true; | |
const GLOBAL_BOOLEAN = true; | |
let GLOBAL_LET = 'a string'; | |
const BadPropertyNames = { | |
UPPERCASE_PROPERTY: 13, | |
lowercase_property: 13, | |
'UPPERCASE': 13, | |
}; | |
function test() { | |
const LOCAL_CONST = 'a string'; | |
} |
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
✖ 17:7 Variable name global_const must match one of the following formats: strictCamelCase, UPPER_CASE | |
✖ 18:5 Variable name nonconstantboolean must have one of the following prefixes: is, has, can, should, will, did | |
✖ 19:7 Variable name isglobalboolean trimmed as globalboolean must match one of the following formats: StrictPascalCase | |
✖ 20:7 Variable name GLOBAL_BOOLEAN must have one of the following prefixes: IS_, HAS_, CAN_, SHOULD_, WILL_, DID_ | |
✖ 21:5 Variable name GLOBAL_LET must match one of the following formats: strictCamelCase | |
✖ 22:7 Variable name BadPropertyNames must match one of the following formats: strictCamelCase, UPPER_CASE | |
✖ 23:2 Object Literal Property name UPPERCASE_PROPERTY must match one of the following formats: strictCamelCase | |
✖ 24:2 Object Literal Property name lowercase_property must match one of the following formats: strictCamelCase | |
✖ 25:2 Object Literal Property name UPPERCASE must match one of the following formats: strictCamelCase | |
✖ 28:8 Variable name LOCAL_CONST must match one of the following formats: strictCamelCase |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment