0.0.11
This commit is contained in:
parent
d14e999d04
commit
3e409c2b95
27 changed files with 1235 additions and 997 deletions
81
rules/astro.ts
Normal file
81
rules/astro.ts
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* eslint-disable unicorn/no-null -- Le null est nécessaire ici. */
|
||||
|
||||
import type { Linter } from "eslint";
|
||||
|
||||
import * as astroEsLintParser from "astro-eslint-parser";
|
||||
import astro from "eslint-plugin-astro";
|
||||
import globals from "globals";
|
||||
import typeScriptEsLint from "typescript-eslint";
|
||||
|
||||
export const astroRules: ReadonlyArray<Linter.Config> = [
|
||||
{
|
||||
files: ["**/*.astro"],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.astro,
|
||||
},
|
||||
parser: astroEsLintParser,
|
||||
parserOptions: {
|
||||
extraFileExtensions: [".astro"],
|
||||
parser: typeScriptEsLint.parser,
|
||||
project: true,
|
||||
projectService: null,
|
||||
tsconfigRootDir: null,
|
||||
},
|
||||
sourceType: "module",
|
||||
},
|
||||
name: "Astro",
|
||||
plugins: {
|
||||
astro: astro.configs.base[0]?.plugins.astro ?? {},
|
||||
},
|
||||
processor: "astro/client-side-ts",
|
||||
rules: {
|
||||
// This rule reports not setting a value for the client:only directive.
|
||||
"astro/missing-client-only-directive-value": "error",
|
||||
// This rule reports conflicting set:text, set:html, and child content.
|
||||
"astro/no-conflict-set-directives": "error",
|
||||
// This rule reports use of deprecated Astro.canonicalURL.
|
||||
"astro/no-deprecated-astro-canonicalurl": "error",
|
||||
// This rule reports use of deprecated Astro.fetchContent().
|
||||
"astro/no-deprecated-astro-fetchcontent": "error",
|
||||
// This rule reports use of deprecated Astro.resolve().
|
||||
"astro/no-deprecated-astro-resolve": "error",
|
||||
// This rule reports use of deprecated getEntryBySlug().
|
||||
"astro/no-deprecated-getentrybyslug": "error",
|
||||
// This rule reports value exports from Astro components. The use of typed exports are still allowed.
|
||||
"astro/no-exports-from-components": "error",
|
||||
// This rule reports all uses of set:html in order to reduce the risk of injecting potentially unsafe / unescaped html into the browser leading to Cross-Site Scripting (XSS) attacks.
|
||||
"astro/no-set-html-directive": "error",
|
||||
// This rule reports all uses of set:text directive.
|
||||
"astro/no-set-text-directive": "error",
|
||||
// This rule aims to remove unused CSS selectors.
|
||||
"astro/no-unused-css-selector": "error",
|
||||
// This rule is aimed at eliminating unused defined variables in define:vars={...} in style tag.
|
||||
"astro/no-unused-define-vars-in-style": "error",
|
||||
// This rule aims to replace the class attribute with expression with the class:list directive.
|
||||
"astro/prefer-class-list-directive": "error",
|
||||
// This rule aims to replace the class attribute with expression with the class:list directive.
|
||||
"astro/prefer-object-class-list": "error",
|
||||
// This rule aims to use split array elements than string concatenation in class:list.
|
||||
"astro/prefer-split-class-list": ["error", { splitLiteral: false }],
|
||||
// This rule ensures that attributes are sorted, making the structure of your elements more predictable and easier to manage.
|
||||
"astro/sort-attributes": ["error", { ignoreCase: false, order: "asc", type: "alphabetical" }],
|
||||
// This rule uses @astrojs/compiler to check the source code.
|
||||
"astro/valid-compile": "error",
|
||||
// TODO: Sélectionner manuellement les règles.
|
||||
...astro.configs["jsx-a11y-strict"][4]?.rules,
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["**/*.astro/*.ts"],
|
||||
languageOptions: {
|
||||
globals: { ...globals.browser },
|
||||
parser: typeScriptEsLint.parser,
|
||||
parserOptions: {
|
||||
project: null,
|
||||
},
|
||||
sourceType: "module",
|
||||
},
|
||||
name: "Astro/TypeScript",
|
||||
},
|
||||
];
|
||||
25
rules/functional.ts
Normal file
25
rules/functional.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import type { Linter } from "eslint";
|
||||
|
||||
import functional from "eslint-plugin-functional";
|
||||
import typescriptEslint from "typescript-eslint";
|
||||
|
||||
export const functionalRules: Readonly<Linter.Config> = {
|
||||
name: "Programmation fonctionnelle",
|
||||
plugins: { functional: functional as typeof typescriptEslint.plugin },
|
||||
rules: {
|
||||
...functional.configs.noExceptions.rules,
|
||||
...functional.configs.noMutations.rules,
|
||||
...functional.configs.externalTypeScriptRecommended.rules,
|
||||
...functional.configs.stylistic.rules,
|
||||
// Choix stylistique.
|
||||
"@typescript-eslint/array-type": ["error", { default: "generic", readonly: "generic" }],
|
||||
// L'imposition d'une immutabilité plus importante est extrêmement contraignante et réduit la lisibilité du code.
|
||||
"functional/prefer-immutable-types": "off",
|
||||
// Le style tacite complique la lecture du code.
|
||||
"functional/prefer-tacit": "off",
|
||||
// Choix stylistique.
|
||||
"functional/readonly-type": ["error", "generic"],
|
||||
// L'imposition d'une immutabilité plus importante est extrêmement contraignante et réduit la lisibilité du code.
|
||||
"functional/type-declaration-immutability": "off",
|
||||
},
|
||||
};
|
||||
63
rules/javascript.ts
Normal file
63
rules/javascript.ts
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import type { Linter } from "eslint";
|
||||
|
||||
import javascript from "@eslint/js";
|
||||
|
||||
export const javascriptRules: Readonly<Linter.Config> = {
|
||||
name: "JavaScript",
|
||||
rules: {
|
||||
...javascript.configs.recommended.rules,
|
||||
/**
|
||||
* Impose la présence de déclarations `return` dans les _callbacks_ des méthodes `Array`.
|
||||
*
|
||||
* Il est autorisé ici l'usage de valeurs de retour en `void` et la vérification de valeurs de retour superflues
|
||||
* pour `forEach()`.
|
||||
*
|
||||
* @link [ESLint](https://eslint.org/docs/latest/rules/array-callback-return)
|
||||
*/
|
||||
"array-callback-return": ["error", { allowVoid: true, checkForEach: true }],
|
||||
/** Surchargé par une meilleur version présente dans le plugin _Unicorn_. */
|
||||
"no-nested-ternary": "off",
|
||||
/**
|
||||
* Interdit l'usage de variables lues sans être préalablement assignées.
|
||||
*
|
||||
* @link [ESLint](https://eslint.org/docs/latest/rules/no-unassigned-vars)
|
||||
*/
|
||||
"no-unassigned-vars": "error",
|
||||
/**
|
||||
* Interdit l'usage d'opérateurs ternaires quand des opérations plus simples existent. Cela inclut ici l'usage de
|
||||
* ternaires comme opération d'assignation par défaut d'une valeur.
|
||||
*
|
||||
* @link [ESLint](https://eslint.org/docs/latest/rules/no-unneeded-ternary)
|
||||
*/
|
||||
"no-unneeded-ternary": ["error", { defaultAssignment: false }],
|
||||
/**
|
||||
* Interdit l'usage de boucles ne permettant qu'une seule itération. Par la nature de l'analyse statique de code,
|
||||
* certains cas peuvent ne pas être détectées.
|
||||
*
|
||||
* @link [ESLint](https://eslint.org/docs/latest/rules/no-unreachable-loop)
|
||||
*/
|
||||
"no-unreachable-loop": "error",
|
||||
/**
|
||||
* Interdit l'utilisation d'une variable avant sa définition.
|
||||
*
|
||||
* La règle est désactivée ici pour que l'ordre de déclaration au sein d'un module n'ait pas d'importance.
|
||||
*
|
||||
* @link [ESLint](https://eslint.org/docs/latest/rules/no-use-before-define)
|
||||
*/
|
||||
"no-use-before-define": "off",
|
||||
/**
|
||||
* Interdit l'assignation de variables non utilisées. Par la nature de l'analyse statique de code, certains cas
|
||||
* peuvent ne pas être détectées.
|
||||
*
|
||||
* @link [ESLint](https://eslint.org/docs/latest/rules/no-useless-assignment)
|
||||
*/
|
||||
"no-useless-assignment": "error",
|
||||
/**
|
||||
* Interdit ici l'usage de conditions « [Yoda](https://en.wikipedia.org/wiki/Yoda_conditions) » pour des soucis de
|
||||
* lisibilité du code.
|
||||
*
|
||||
* @link [ESLint](https://eslint.org/docs/latest/rules/yoda)
|
||||
*/
|
||||
yoda: ["error", "never"],
|
||||
},
|
||||
};
|
||||
77
rules/jsdoc.ts
Normal file
77
rules/jsdoc.ts
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
import type { Linter } from "eslint";
|
||||
|
||||
import jsdoc from "eslint-plugin-jsdoc";
|
||||
|
||||
const flatRecommended = jsdoc.configs["flat/recommended-typescript"];
|
||||
const flatStylistic = jsdoc.configs["flat/stylistic-typescript"];
|
||||
|
||||
export const jsDocRules: Readonly<Linter.Config> = {
|
||||
name: "JSDoc",
|
||||
plugins: flatRecommended.plugins ?? {},
|
||||
rules: {
|
||||
...flatRecommended.rules,
|
||||
...flatStylistic.rules,
|
||||
/**
|
||||
* Vérifie que l'indentation au sein des blocs _JSDoc_ est cohérente.
|
||||
*
|
||||
* @link [GitHub](https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-indentation.md)
|
||||
*/
|
||||
"jsdoc/check-indentation": "warn",
|
||||
/**
|
||||
* TODO: Finir la description.
|
||||
*
|
||||
* @link [GitHub](https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-line-alignment.md)
|
||||
*/
|
||||
"jsdoc/check-line-alignment": "warn",
|
||||
/**
|
||||
* TODO: Finir la description.
|
||||
*
|
||||
* @link [GitHub](https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-tag-names.md)
|
||||
*/
|
||||
"jsdoc/check-tag-names": ["warn", { definedTags: ["link"] }],
|
||||
/**
|
||||
* TODO: Finir la description
|
||||
*
|
||||
* @link [GitHub](https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/lines-before-block.md)
|
||||
*/
|
||||
"jsdoc/lines-before-block": "off",
|
||||
/**
|
||||
* TODO: Finir la description.
|
||||
*
|
||||
* @link [GitHub](https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/no-blank-block-descriptions.md)
|
||||
*/
|
||||
"jsdoc/no-blank-block-descriptions": "warn",
|
||||
/**
|
||||
* TODO: Finir la description.
|
||||
*
|
||||
* @link [GitHub](https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/no-blank-blocks.md)
|
||||
*/
|
||||
"jsdoc/no-blank-blocks": "warn",
|
||||
/**
|
||||
* TODO: Finir la description.
|
||||
*
|
||||
* @link [GitHub](https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-hyphen-before-param-description.md)
|
||||
*/
|
||||
"jsdoc/require-hyphen-before-param-description": ["warn", "never"],
|
||||
/**
|
||||
* TODO: Finir la description.
|
||||
*
|
||||
* @link [GitHub](https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-throws.md)
|
||||
*/
|
||||
"jsdoc/require-throws": "warn",
|
||||
/**
|
||||
* TODO: Finir la description.
|
||||
*
|
||||
* @link [GitHub](https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/sort-tags.md)
|
||||
*/
|
||||
"jsdoc/sort-tags": "warn",
|
||||
/**
|
||||
* Impose la présence de lignes (ou non) entre les _tags_.
|
||||
*
|
||||
* Désactivé ici car elle rentre en conflit avec l'extension _Prettier_ pour _JSDoc_.
|
||||
*
|
||||
* @link [GitHub](https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/tag-lines.md)
|
||||
*/
|
||||
"jsdoc/tag-lines": "off",
|
||||
},
|
||||
};
|
||||
17
rules/sonarjs.ts
Normal file
17
rules/sonarjs.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import type { Linter } from "eslint";
|
||||
|
||||
import sonarJs from "eslint-plugin-sonarjs";
|
||||
|
||||
export const sonarJsRules: Readonly<Linter.Config> = {
|
||||
name: "SonarJS",
|
||||
plugins: sonarJs.configs.recommended.plugins ?? {},
|
||||
rules: {
|
||||
...sonarJs.configs.recommended.rules,
|
||||
"sonarjs/arguments-usage": "error",
|
||||
"sonarjs/no-collapsible-if": "error",
|
||||
"sonarjs/no-duplicate-string": "error",
|
||||
"sonarjs/no-inconsistent-returns": "error",
|
||||
"sonarjs/no-nested-switch": "error",
|
||||
"sonarjs/prefer-immediate-return": "error",
|
||||
},
|
||||
};
|
||||
9
rules/tri.ts
Normal file
9
rules/tri.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import type { Linter } from "eslint";
|
||||
|
||||
import perfectionist from "eslint-plugin-perfectionist";
|
||||
|
||||
export const sortRules: Readonly<Linter.Config> = {
|
||||
name: "Tri",
|
||||
plugins: perfectionist.configs["recommended-natural"].plugins ?? {},
|
||||
rules: perfectionist.configs["recommended-natural"].rules ?? {},
|
||||
};
|
||||
78
rules/typescript.ts
Normal file
78
rules/typescript.ts
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import type { Linter } from "eslint";
|
||||
|
||||
import typescriptEslint from "typescript-eslint";
|
||||
|
||||
type EsLintConfig = Readonly<Linter.Config>;
|
||||
|
||||
const findConfiguration = (configuration: ReadonlyArray<Linter.Config>, nom: string): EsLintConfig =>
|
||||
configuration.find((v: EsLintConfig) => v.name === nom) ?? {};
|
||||
|
||||
const base = findConfiguration(typescriptEslint.configs.strictTypeChecked, "typescript-eslint/base");
|
||||
const desactivationsJavaScript = findConfiguration(
|
||||
typescriptEslint.configs.strictTypeChecked,
|
||||
"typescript-eslint/eslint-recommended",
|
||||
);
|
||||
const strictTypeChecked = findConfiguration(
|
||||
typescriptEslint.configs.strictTypeChecked,
|
||||
"typescript-eslint/strict-type-checked",
|
||||
);
|
||||
const stylisticTypeChecked = findConfiguration(
|
||||
typescriptEslint.configs.stylisticTypeChecked,
|
||||
"typescript-eslint/stylistic-type-checked",
|
||||
);
|
||||
|
||||
export const typeScriptRules: 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",
|
||||
},
|
||||
};
|
||||
79
rules/unicorn.ts
Normal file
79
rules/unicorn.ts
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
import type { Linter } from "eslint";
|
||||
|
||||
import unicorn from "eslint-plugin-unicorn";
|
||||
|
||||
export const unicornRules: Readonly<Linter.Config> = {
|
||||
name: "Unicorn",
|
||||
plugins: { unicorn: unicorn },
|
||||
rules: {
|
||||
...unicorn.configs.unopinionated.rules,
|
||||
/**
|
||||
* Impose un nom de paramètre spécifique dans les clauses de capture des Erreurs.
|
||||
*
|
||||
* @link [GitHub](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/catch-error-name.md)
|
||||
*/
|
||||
"unicorn/catch-error-name": "error",
|
||||
/**
|
||||
* Préfère des types consistants lors de l'étalage d'un tableau de littéraux au sein d'une condition ternaire.
|
||||
*
|
||||
* @link [GitHub](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/consistent-empty-array-spread.md)
|
||||
*/
|
||||
"unicorn/consistent-empty-array-spread": "error",
|
||||
/**
|
||||
* Impose l'unique manière valide d'étendre la classe `Error`.
|
||||
*
|
||||
* @link [GitHub](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/custom-error-definition.md)
|
||||
*/
|
||||
"unicorn/custom-error-definition": "error",
|
||||
/**
|
||||
* Impose la comparaison explicite de propriétés `length` ou `size`. Cela inclut ici l'obligation de vérifier
|
||||
* qu'elles ne correspondent pas à `0` avec `!==`.
|
||||
*
|
||||
* @link [GitHub](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/explicit-length-check.md)
|
||||
*/
|
||||
"unicorn/explicit-length-check": ["error", { "non-zero": "not-equal" }],
|
||||
/**
|
||||
* Autorise ici l'usage de la méthode `forEach()` des tableaux.
|
||||
*
|
||||
* Je préfère cette méthode (ou celle de la librairie _Effect_) aux boucles.
|
||||
*
|
||||
* @link [GitHub](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-for-each.md)
|
||||
*/
|
||||
"unicorn/no-array-for-each": "off",
|
||||
/**
|
||||
* Autorise ici l'usage de la méthode `reduce()` des tableaux.
|
||||
*
|
||||
* J'utilise occasionnellement cette méthode pour des opérations simples.
|
||||
*
|
||||
* @link [GitHub](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-for-each.md)
|
||||
*/
|
||||
"unicorn/no-array-reduce": "off",
|
||||
/**
|
||||
* Interdit l'usage de conditions négatives pour la clarté du code.
|
||||
*
|
||||
* @link [GitHub](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-negated-condition.md)
|
||||
*/
|
||||
"unicorn/no-negated-condition": "error",
|
||||
/**
|
||||
* Interdit l'usage d'opérateurs ternaires imbriqués. Cette règle remplace celle présente par défaut dans _ESLint_
|
||||
* avec le même nom.
|
||||
*
|
||||
* @link [GitHub](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-nested-ternary.md)
|
||||
*/
|
||||
"unicorn/no-nested-ternary": "error",
|
||||
/**
|
||||
* Interdit l'usage de `null`.
|
||||
*
|
||||
* @link [GitHub](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-null.md)
|
||||
*/
|
||||
"unicorn/no-null": "error",
|
||||
/**
|
||||
* N'impose pas ici l'usage de `.dataset` pour l'interaction avec les attributs d'Éléments DOM.
|
||||
*
|
||||
* L'ergonomie est réduite comparée aux méthodes `{get,has,set,remove}Attribute()`.
|
||||
*
|
||||
* @link [GitHub](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-dom-node-dataset.md)
|
||||
*/
|
||||
"unicorn/prefer-dom-node-dataset": "off",
|
||||
},
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue