Skip to content

Commit

Permalink
Allow pascal-case in .tsx files (#50)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
younho9 and sindresorhus authored Jan 6, 2022
1 parent 22866b3 commit 1105aa8
Showing 1 changed file with 84 additions and 70 deletions.
154 changes: 84 additions & 70 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,79 @@
'use strict';

const getNamingConventionRule = ({isTsx}) => ({
"@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',
isTsx && 'StrictPascalCase',
].filter(Boolean),
// We allow double underscore because of GraphQL type names and some React names.
leadingUnderscore: 'allowSingleOrDouble',
trailingUnderscore: 'allow',
// Ignore `{'Retry-After': retryAfter}` type properties.
filter: {
regex: '[- ]',
match: false
}
},
{
selector: 'typeLike',
format: [
'StrictPascalCase'
]
},
{
selector: 'variable',
types: [
'boolean'
],
format: [
'StrictPascalCase'
],
prefix: [
'is',
'has',
'can',
'should',
'will',
'did'
]
},
{
// 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'
]
}
]
});

module.exports = {
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: {
Expand Down Expand Up @@ -274,76 +349,7 @@ module.exports = {
// - https://github.com/typescript-eslint/typescript-eslint/issues/1485
// - https://github.com/typescript-eslint/typescript-eslint/issues/1484
// TODO: Prevent `_` prefix on private fields when TypeScript 3.8 is out.
'@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',
// Ignore `{'Retry-After': retryAfter}` type properties.
filter: {
regex: '[- ]',
match: false
}
},
{
selector: 'typeLike',
format: [
'StrictPascalCase'
]
},
{
selector: 'variable',
types: [
'boolean'
],
format: [
'StrictPascalCase'
],
prefix: [
'is',
'has',
'can',
'should',
'will',
'did'
]
},
{
// 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'
]
}
],
...getNamingConventionRule({isTsx: false}),
'@typescript-eslint/no-base-to-string': 'error',
'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor': 'error',
Expand Down Expand Up @@ -674,6 +680,14 @@ module.exports = {
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-confusing-void-expression': 'off' // Conflicts with `expectError` assertion.
}
},
{
files: [
'**/*.tsx'
],
rules: {
...getNamingConventionRule({isTsx: true})
}
}
]
};

0 comments on commit 1105aa8

Please sign in to comment.