78 lines
3.1 KiB
TypeScript
78 lines
3.1 KiB
TypeScript
import type { Linter } from "eslint";
|
|
|
|
import typescriptEslint from "typescript-eslint";
|
|
|
|
type EsLintConfig = Readonly<Linter.Config>;
|
|
|
|
const trouveConfiguration = (configuration: ReadonlyArray<Linter.Config>, nom: string): EsLintConfig =>
|
|
configuration.find((v: EsLintConfig) => v.name === nom) ?? {};
|
|
|
|
const base = trouveConfiguration(typescriptEslint.configs.strictTypeChecked, "typescript-eslint/base");
|
|
const desactivationsJavaScript = trouveConfiguration(
|
|
typescriptEslint.configs.strictTypeChecked,
|
|
"typescript-eslint/eslint-recommended",
|
|
);
|
|
const strictTypeChecked = trouveConfiguration(
|
|
typescriptEslint.configs.strictTypeChecked,
|
|
"typescript-eslint/strict-type-checked",
|
|
);
|
|
const stylisticTypeChecked = trouveConfiguration(
|
|
typescriptEslint.configs.stylisticTypeChecked,
|
|
"typescript-eslint/stylistic-type-checked",
|
|
);
|
|
|
|
export const règlesTypeScript: Readonly<Linter.Config> = {
|
|
languageOptions: base.languageOptions ?? {},
|
|
name: "TypeScript",
|
|
plugins: base.plugins ?? {},
|
|
rules: {
|
|
...desactivationsJavaScript.rules,
|
|
...strictTypeChecked.rules,
|
|
...stylisticTypeChecked.rules,
|
|
/**
|
|
* Impose un usage consistant entre interfaces et types. Ici préfère les déclarations de types.
|
|
*
|
|
* @link [typescript-eslint](https://typescript-eslint.io/rules/consistent-type-definitions)
|
|
*/
|
|
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
|
|
/**
|
|
* Interdit la définition de fonctions avec plus de 3 paramètres.
|
|
*
|
|
* @link [typescript-eslint](https://eslint.org/docs/latest/rules/max-params)
|
|
*/
|
|
"@typescript-eslint/max-params": ["error", { max: 3 }],
|
|
/**
|
|
* Impose une syntaxe particulière pour les signatures de méthodes au sein d'interfaces et types. Ici utilise la
|
|
* syntaxe « propriété ».
|
|
*
|
|
* ```typescript
|
|
* interface Exemple {
|
|
* func: (arg: string) => number;
|
|
* }
|
|
* ```
|
|
*
|
|
* @link [typescript-eslint](https://typescript-eslint.io/rules/method-signature-style/)
|
|
*/
|
|
"@typescript-eslint/method-signature-style": ["off", "property"],
|
|
/**
|
|
* Interdit l'usage de nombres magiques. Cette règle étend
|
|
* [no-magic-numbers](https://eslint.org/docs/latest/rules/no-magic-numbers) de la configuration de base _ESLint_.
|
|
*
|
|
* @link [typescript-eslint](https://eslint.org/docs/latest/rules/no-magic-numbers)
|
|
*/
|
|
"@typescript-eslint/no-magic-numbers": "off",
|
|
/**
|
|
* Autorise ici la comparaison avec des littéraux booléens. La désactivation de cette règle permet des comparaisons
|
|
* plus claires qu'avec l'opérateur de négation `!`.
|
|
*
|
|
* @link [typescript-eslint](https://typescript-eslint.io/rules/no-unnecessary-boolean-literal-compare)
|
|
*/
|
|
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "off",
|
|
/**
|
|
* Interdit l'usage de paramètres de types non utilisés plusieurs fois. Désactivé ici à cause de faux positifs.
|
|
*
|
|
* @link [typescript-eslint](https://typescript-eslint.io/rules/no-unnecessary-type-parameters)
|
|
*/
|
|
"@typescript-eslint/no-unnecessary-type-parameters": "off",
|
|
},
|
|
};
|