Skip to content

Commit

Permalink
fix: naming-convention errors
Browse files Browse the repository at this point in the history
Added some basic tests for current cases for naming-convention as it’s very complicated.
  • Loading branch information
SimeonC committed Dec 5, 2023
1 parent 699d82a commit 4821395
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 9 deletions.
3 changes: 0 additions & 3 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@
"files": [
"dist"
],
"scripts": {
"build": "tsc -p ./tsconfig.build.json"
},
"dependencies": {
"@emotion/eslint-plugin": "^11.11.0",
"@nx/eslint-plugin": "^16.5.0",
Expand Down
20 changes: 20 additions & 0 deletions packages/eslint-config/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@
"sourceRoot": "packages/eslint-config/src",
"projectType": "library",
"targets": {
"build": {
"executor": "nx:run-commands",
"options": {
"command": "tsc -p packages/eslint-config/tsconfig.build.json"
}
},
"test": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"dependsOn": ["build"],
"options": {
"noEslintrc": true,
"eslintConfig": "packages/eslint-config/tests/.eslintrc.cjs",
"reportUnusedDisableDirectives": "error",
"lintFilePatterns": [
"packages/eslint-config/tests/**/*.ts",
"packages/eslint-config/tests/**/*.tsx"
]
}
},
"quality": {
"executor": "@tablecheck/nx:quality",
"outputs": ["{options.outputFile}"],
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/src/presets/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
...promiseRules,
...emotionRules,
...namingRules,
'no-unused-vars': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
},
}),
Expand All @@ -30,7 +31,6 @@ module.exports = {
rules: {
'import/no-default-export': 'off',
'vars-on-top': 'off',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-empty-interface': 'warn',
'@typescript-eslint/explicit-module-boundary-types': 'off',
Expand Down
17 changes: 12 additions & 5 deletions packages/eslint-config/src/rules/namingConvention.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import type { Linter } from 'eslint';

const componentRegexpMatch = {
regex: '(?<![gs]et)Component$',
match: true,
};

export const namingRules: Linter.RulesRecord = {
camelcase: 'off',
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'default',
format: ['PascalCase'],
filter: {
regex: '(?<![gs]et)Component($|[A-Z0-9])',
match: true,
},
format: ['camelCase', 'PascalCase'],
filter: componentRegexpMatch,
},
{
selector: 'default',
Expand Down Expand Up @@ -81,6 +83,11 @@ export const namingRules: Linter.RulesRecord = {
modifiers: ['global'],
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
},
{
selector: 'variable',
format: ['PascalCase'],
filter: componentRegexpMatch,
},
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE'],
Expand Down
12 changes: 12 additions & 0 deletions packages/eslint-config/tests/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { namingRules } = require('../dist/rules/namingConvention');

module.exports = {
plugins: ['@typescript-eslint'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: true,
},
rules: namingRules,
};
13 changes: 13 additions & 0 deletions packages/eslint-config/tests/namingConvention.ts/variables.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** Booleans */
// eslint-disable-next-line @typescript-eslint/naming-convention
const badName = true;
const isBadName = true;
const disabled = true;

/** Dereferencing */
function SomeComponent({ icon: Icon, command }) {
const { icon: IconComponent } = command;
// eslint-disable-next-line @typescript-eslint/naming-convention
const { other: Other } = command;
const iconComponentRef = null;
}
14 changes: 14 additions & 0 deletions packages/eslint-config/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../tsconfig.json",
"include": ["**/*.ts", "**/*.tsx"],
"compilerOptions": {
"rootDir": ".",
"outDir": "dist",
"paths": {},
"types": ["vitest"],
"module": "NodeNext",
"resolveJsonModule": true
},
"exclude": ["node_modules"],
"files": []
}

0 comments on commit 4821395

Please sign in to comment.