Skip to content

Commit

Permalink
refactor: typescript rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Badisi committed Oct 30, 2024
1 parent f28f3b0 commit 1f95171
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 151 deletions.
81 changes: 77 additions & 4 deletions configs/typescript/recommended.mjs → configs/typescript.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import tsPlugin from 'typescript-eslint';

import { namingConventions } from './utils.mjs';
const UPPER_CASE_REGEXP = [
// url params
'PATIENT_ID',
'SCOPEID',
'SESSIONID',
'EDS_ID',
'DOCPAGE',

// proxy call
'REQUEST',
'SERVERID',
'SERVICEID',
'SUBSERVICEID'
];

/** @type {(files?: Array<string | string[]>) => (import('eslint').Linter.Config)[]} */
export default files =>
Expand Down Expand Up @@ -40,9 +53,8 @@ export default files =>
{
accessibility: 'explicit',
overrides: {
constructors: 'explicit',
constructors: 'no-public',
accessors: 'explicit',
methods: 'off',
parameterProperties: 'explicit'
}
}
Expand Down Expand Up @@ -134,7 +146,68 @@ export default files =>
// https://typescript-eslint.io/rules/naming-convention
'@typescript-eslint/naming-convention': [
'error',
...namingConventions()
{
selector: 'default',
format: ['strictCamelCase'],
leadingUnderscore: 'allow'
},
{
selector: 'typeLike',
format: ['PascalCase']
},
{
selector: 'enumMember',
format: ['UPPER_CASE']
},
{
selector: 'typeProperty',
format: ['UPPER_CASE'],
filter: {
regex: `^(${UPPER_CASE_REGEXP.join('|')})$`,
match: true
}
},
{
selector: 'objectLiteralProperty',
format: ['UPPER_CASE'],
filter: {
regex: `^(${UPPER_CASE_REGEXP.join('|')})$`,
match: true
}
},
{
selector: 'property',
modifiers: ['static'],
format: ['UPPER_CASE'],
leadingUnderscore: 'allow'
},
{
selector: 'property',
format: [
'strictCamelCase',
'UPPER_CASE'
],
leadingUnderscore: 'allow'
},
{
selector: 'parameter',
format: ['strictCamelCase'],
leadingUnderscore: 'allow'
},
{
selector: 'variable',
format: [
'strictCamelCase',
'UPPER_CASE'
],
types: [
'boolean',
'string',
'number',
'array'
],
leadingUnderscore: 'allow'
}
],

// Disallow variable declarations from shadowing variables declared in the outer scope
Expand Down
7 changes: 0 additions & 7 deletions configs/typescript/index.mjs

This file was deleted.

65 changes: 0 additions & 65 deletions configs/typescript/moderate.mjs

This file was deleted.

73 changes: 0 additions & 73 deletions configs/typescript/utils.mjs

This file was deleted.

4 changes: 2 additions & 2 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import preferArrow from './configs/prefer-arrow.mjs';
import prettier from './configs/prettier.mjs';
import rxjs from './configs/rxjs/index.mjs';
import simpleImportSort from './configs/simple-import-sort.mjs';
import ts from './configs/typescript/index.mjs';
import typescript from './configs/typescript.mjs';
import unusedImports from './configs/unused-imports.mjs';

/** @type {(name: string) => Promise<boolean>} */
Expand All @@ -35,7 +35,7 @@ const isPackageInstalled = async name => {
/** @type { (level: 'moderate' | 'recommended') => Promise<import('eslint').Linter.Config[]> } */
const getConfig = async level => [
eslint(['**/*.{ts,js,mjs,cjs}']),
...((await isPackageInstalled('typescript')) ? ts[level](['**/*.ts']) : []),
...((await isPackageInstalled('typescript')) ? typescript(['**/*.ts']) : []),
(await isPackageInstalled('rxjs')) ? rxjs[level].ts(['**/*.ts']) : {},
...((await isPackageInstalled('@angular/core')) ? [
...angular[level].ts(['**/*.ts']),
Expand Down

0 comments on commit 1f95171

Please sign in to comment.