Use eslint to lint the eslint-config package itself
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
2
package-lock.json
generated
2
package-lock.json
generated
@@ -13593,13 +13593,13 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@eslint/js": "^9.39.2",
|
"@eslint/js": "^9.39.2",
|
||||||
"@stylistic/eslint-plugin": "^5.7.0",
|
"@stylistic/eslint-plugin": "^5.7.0",
|
||||||
"eslint": "^9.39.2",
|
|
||||||
"eslint-plugin-react": "^7.37.5",
|
"eslint-plugin-react": "^7.37.5",
|
||||||
"eslint-plugin-react-hooks": "^7.0.1",
|
"eslint-plugin-react-hooks": "^7.0.1",
|
||||||
"globals": "^17.0.0",
|
"globals": "^17.0.0",
|
||||||
"typescript-eslint": "^8.53.1"
|
"typescript-eslint": "^8.53.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"eslint": "^9.39.2",
|
||||||
"typescript": "^5.8.3"
|
"typescript": "^5.8.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
20
packages/eslint-config/eslint.config.js
Normal file
20
packages/eslint-config/eslint.config.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { defineConfig } from "eslint/config";
|
||||||
|
|
||||||
|
import { baseConfigs } from "./src/baseConfigs.ts";
|
||||||
|
import { tsConfigs } from "./src/tsConfigs.ts";
|
||||||
|
import { nodeLanguageOptionsConfig } from "./src/languageOptionsConfigs.ts";
|
||||||
|
import { stylisticConfigs } from "./src/stylisticConfigs.ts";
|
||||||
|
|
||||||
|
export default defineConfig([
|
||||||
|
...baseConfigs,
|
||||||
|
...tsConfigs,
|
||||||
|
nodeLanguageOptionsConfig,
|
||||||
|
...stylisticConfigs,
|
||||||
|
{
|
||||||
|
languageOptions: {
|
||||||
|
parserOptions: {
|
||||||
|
tsConfigRootDir: import.meta.dirname,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
import js from "@eslint/js";
|
|
||||||
import globals from "globals";
|
|
||||||
import reactHooks from "eslint-plugin-react-hooks";
|
|
||||||
import tseslint from "typescript-eslint";
|
|
||||||
import stylistic from "@stylistic/eslint-plugin";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base ESLint configuration with strict and stylistic rules
|
|
||||||
*/
|
|
||||||
export function createConfig({
|
|
||||||
files = ["**/*.{ts,tsx}"],
|
|
||||||
languageOptions = {},
|
|
||||||
react = false,
|
|
||||||
project = true,
|
|
||||||
tsconfigRootDir,
|
|
||||||
} = {}) {
|
|
||||||
const configs = [
|
|
||||||
{ ignores: ["dist", "node_modules", "**/*.d.ts"] },
|
|
||||||
js.configs.recommended,
|
|
||||||
...tseslint.configs.recommendedTypeChecked,
|
|
||||||
{
|
|
||||||
files,
|
|
||||||
languageOptions: (() => {
|
|
||||||
const mergedGlobals = {
|
|
||||||
...globals.node,
|
|
||||||
...globals.es2021,
|
|
||||||
...(languageOptions.globals || {}),
|
|
||||||
};
|
|
||||||
const mergedParserOptions = {
|
|
||||||
project,
|
|
||||||
...(tsconfigRootDir && { tsconfigRootDir }),
|
|
||||||
...(languageOptions.parserOptions || {}),
|
|
||||||
};
|
|
||||||
const otherLanguageOptions = Object.fromEntries(
|
|
||||||
Object.entries(languageOptions).filter(
|
|
||||||
([key]) => key !== "globals" && key !== "parserOptions",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
ecmaVersion: 2020,
|
|
||||||
sourceType: "module",
|
|
||||||
globals: mergedGlobals,
|
|
||||||
parserOptions: mergedParserOptions,
|
|
||||||
...otherLanguageOptions,
|
|
||||||
};
|
|
||||||
})(),
|
|
||||||
plugins: {
|
|
||||||
"@stylistic": stylistic,
|
|
||||||
},
|
|
||||||
rules: {
|
|
||||||
// TypeScript strict rules
|
|
||||||
"@typescript-eslint/no-unused-vars": [
|
|
||||||
"error",
|
|
||||||
{
|
|
||||||
argsIgnorePattern: "^_",
|
|
||||||
varsIgnorePattern: "^_",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"@typescript-eslint/explicit-function-return-type": "off",
|
|
||||||
"@typescript-eslint/no-explicit-any": "warn",
|
|
||||||
"@typescript-eslint/no-floating-promises": "error",
|
|
||||||
"@typescript-eslint/no-misused-promises": "error",
|
|
||||||
"@typescript-eslint/await-thenable": "error",
|
|
||||||
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
|
||||||
|
|
||||||
// Stylistic rules
|
|
||||||
"@stylistic/quotes": ["error", "double", { avoidEscape: true }],
|
|
||||||
"@stylistic/semi": ["error", "always"],
|
|
||||||
"@stylistic/comma-dangle": ["error", "always-multiline"],
|
|
||||||
"@stylistic/indent": ["error", 2, { SwitchCase: 1 }],
|
|
||||||
"@stylistic/object-curly-spacing": ["error", "always"],
|
|
||||||
"@stylistic/array-bracket-spacing": ["error", "never"],
|
|
||||||
"@stylistic/comma-spacing": ["error", { before: false, after: true }],
|
|
||||||
"@stylistic/key-spacing": [
|
|
||||||
"error",
|
|
||||||
{ beforeColon: false, afterColon: true },
|
|
||||||
],
|
|
||||||
"@stylistic/space-before-blocks": ["error", "always"],
|
|
||||||
"@stylistic/space-before-function-paren": [
|
|
||||||
"error",
|
|
||||||
{ anonymous: "always", named: "never", asyncArrow: "always" },
|
|
||||||
],
|
|
||||||
"@stylistic/space-infix-ops": "error",
|
|
||||||
"@stylistic/arrow-spacing": ["error", { before: true, after: true }],
|
|
||||||
"@stylistic/no-trailing-spaces": "error",
|
|
||||||
"@stylistic/eol-last": ["error", "always"],
|
|
||||||
"@stylistic/max-len": [
|
|
||||||
"warn",
|
|
||||||
{ code: 120, ignoreUrls: true, ignoreStrings: true },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
if (react) {
|
|
||||||
configs.push({
|
|
||||||
files,
|
|
||||||
plugins: {
|
|
||||||
"react-hooks": reactHooks,
|
|
||||||
},
|
|
||||||
rules: {
|
|
||||||
...reactHooks.configs.recommended.rules,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return configs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Browser/React configuration
|
|
||||||
*/
|
|
||||||
export function browser(project = true, tsconfigRootDir) {
|
|
||||||
return createConfig({
|
|
||||||
files: ["**/*.{ts,tsx}"],
|
|
||||||
languageOptions: {
|
|
||||||
globals: {
|
|
||||||
...globals.browser,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
react: true,
|
|
||||||
project,
|
|
||||||
tsconfigRootDir,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Node.js configuration
|
|
||||||
*/
|
|
||||||
export function node(project = true, tsconfigRootDir) {
|
|
||||||
return createConfig({
|
|
||||||
files: ["**/*.{ts,tsx}"],
|
|
||||||
languageOptions: {
|
|
||||||
globals: {
|
|
||||||
...globals.node,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
react: false,
|
|
||||||
project,
|
|
||||||
tsconfigRootDir,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -3,22 +3,24 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Shared ESLint configuration for Probo monorepo",
|
"description": "Shared ESLint configuration for Probo monorepo",
|
||||||
"main": "eslint.config.mjs",
|
"main": "./src/index.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {},
|
"scripts": {
|
||||||
|
"lint": "eslint src"
|
||||||
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@eslint/js": "^9.39.2",
|
"@eslint/js": "^9.39.2",
|
||||||
"@stylistic/eslint-plugin": "^5.7.0",
|
"@stylistic/eslint-plugin": "^5.7.0",
|
||||||
"eslint": "^9.39.2",
|
|
||||||
"eslint-plugin-react": "^7.37.5",
|
"eslint-plugin-react": "^7.37.5",
|
||||||
"eslint-plugin-react-hooks": "^7.0.1",
|
"eslint-plugin-react-hooks": "^7.0.1",
|
||||||
"globals": "^17.0.0",
|
"globals": "^17.0.0",
|
||||||
"typescript-eslint": "^8.53.1"
|
"typescript-eslint": "^8.53.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"eslint": "^9.39.2",
|
||||||
"typescript": "^5.8.3"
|
"typescript": "^5.8.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import * as js from "@eslint/js";
|
import js from "@eslint/js";
|
||||||
|
|
||||||
export const baseConfigs = [
|
export const baseConfigs = [
|
||||||
{ ignores: ["dist", "node_modules", "**/*.d.ts"] },
|
{ ignores: ["dist", "node_modules", "**/*.d.ts"] },
|
||||||
|
{ files: ["**/*.js", "**/*.ts", "**/*.tsx"] },
|
||||||
js.configs.recommended,
|
js.configs.recommended,
|
||||||
];
|
];
|
||||||
16
packages/eslint-config/src/index.ts
Normal file
16
packages/eslint-config/src/index.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { baseConfigs } from "./baseConfigs";
|
||||||
|
import { browserLanguageOptionsConfig, nodeLanguageOptionsConfig } from "./languageOptionsConfigs";
|
||||||
|
import { tsConfigs } from "./tsConfigs";
|
||||||
|
import { reactConfigs } from "./reactConfigs";
|
||||||
|
import { stylisticConfigs } from "./stylisticConfigs";
|
||||||
|
|
||||||
|
export const configs = {
|
||||||
|
base: baseConfigs,
|
||||||
|
ts: tsConfigs,
|
||||||
|
languageOptions: {
|
||||||
|
browser: browserLanguageOptionsConfig,
|
||||||
|
node: nodeLanguageOptionsConfig,
|
||||||
|
},
|
||||||
|
react: reactConfigs,
|
||||||
|
stylistic: stylisticConfigs,
|
||||||
|
};
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
import { browser, es2022, es2023, node } from "globals"
|
import * as globals from "globals";
|
||||||
|
|
||||||
export const browserLanguageOptionsConfig = {
|
export const browserLanguageOptionsConfig = {
|
||||||
languageOptions: {
|
languageOptions: {
|
||||||
// Same as the ones we use in our tsconfig compilerOptions.lib for browser
|
// Same as the ones we use in our tsconfig compilerOptions.lib for browser
|
||||||
ecmaVersion: 2022,
|
ecmaVersion: 2022,
|
||||||
globals: {
|
globals: {
|
||||||
...browser,
|
...globals.browser,
|
||||||
...es2022,
|
...globals.es2022,
|
||||||
},
|
},
|
||||||
sourceType: "module",
|
sourceType: "module",
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
|
projectService: true,
|
||||||
ecmaFeatures: {
|
ecmaFeatures: {
|
||||||
impliedStrict: true,
|
impliedStrict: true,
|
||||||
},
|
},
|
||||||
@@ -22,11 +23,12 @@ export const nodeLanguageOptionsConfig = {
|
|||||||
// Same as the ones we use in our tsconfig compilerOptions.lib for node
|
// Same as the ones we use in our tsconfig compilerOptions.lib for node
|
||||||
ecmaVersion: 2023,
|
ecmaVersion: 2023,
|
||||||
globals: {
|
globals: {
|
||||||
...node,
|
...globals.node,
|
||||||
...es2023,
|
...globals.es2023,
|
||||||
},
|
},
|
||||||
sourceType: "module",
|
sourceType: "module",
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
|
projectService: true,
|
||||||
ecmaFeatures: {
|
ecmaFeatures: {
|
||||||
impliedStrict: true,
|
impliedStrict: true,
|
||||||
},
|
},
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import stylistic from "@stylistic/eslint-plugin";
|
import stylistic from "@stylistic/eslint-plugin";
|
||||||
|
import { type Linter } from "eslint";
|
||||||
|
|
||||||
export const stylisticConfigs = [
|
export const stylisticConfigs = [
|
||||||
stylistic.configs.customize({
|
stylistic.configs.customize({
|
||||||
@@ -20,5 +21,5 @@ export const stylisticConfigs = [
|
|||||||
{ code: 120, ignoreUrls: true, ignoreStrings: true },
|
{ code: 120, ignoreUrls: true, ignoreStrings: true },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
} satisfies Linter.Config,
|
||||||
];
|
];
|
||||||
23
packages/eslint-config/src/tsConfigs.ts
Normal file
23
packages/eslint-config/src/tsConfigs.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { type Linter } from "eslint";
|
||||||
|
import tseslint from "typescript-eslint";
|
||||||
|
|
||||||
|
export const tsConfigs = [
|
||||||
|
...tseslint.configs.recommendedTypeChecked,
|
||||||
|
{
|
||||||
|
files: ["**/*.{ts,tsx}"],
|
||||||
|
rules: {
|
||||||
|
"@typescript-eslint/no-unused-vars": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
args: "all",
|
||||||
|
argsIgnorePattern: "^_",
|
||||||
|
caughtErrors: "all",
|
||||||
|
caughtErrorsIgnorePattern: "^_",
|
||||||
|
destructuredArrayIgnorePattern: "^_",
|
||||||
|
varsIgnorePattern: "^_",
|
||||||
|
ignoreRestSiblings: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
} satisfies Linter.Config,
|
||||||
|
];
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import tseslint from "typescript-eslint";
|
|
||||||
|
|
||||||
export const tsConfigs = [
|
|
||||||
...tseslint.configs.recommendedTypeChecked,
|
|
||||||
{
|
|
||||||
files: ["**/*.{ts,tsx}"],
|
|
||||||
rules: {
|
|
||||||
"@typescript-eslint/no-unused-vars": [
|
|
||||||
"error",
|
|
||||||
{
|
|
||||||
"args": "all",
|
|
||||||
"argsIgnorePattern": "^_",
|
|
||||||
"caughtErrors": "all",
|
|
||||||
"caughtErrorsIgnorePattern": "^_",
|
|
||||||
"destructuredArrayIgnorePattern": "^_",
|
|
||||||
"varsIgnorePattern": "^_",
|
|
||||||
"ignoreRestSiblings": true
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
{
|
{
|
||||||
"complierOptions": {
|
"compilerOptions": {
|
||||||
"lib": ["ES2023"],
|
"lib": ["ES2023"],
|
||||||
|
"allowJs": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"module": "ESNext",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "nodenext",
|
"moduleResolution": "NodeNext",
|
||||||
"moduleDetection": "force",
|
"moduleDetection": "force",
|
||||||
"verbatimModuleSyntax": true,
|
"verbatimModuleSyntax": true,
|
||||||
"noEmit": true,
|
"noEmit": true,
|
||||||
@@ -14,5 +15,5 @@
|
|||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
"noUncheckedSideEffectImports": true
|
"noUncheckedSideEffectImports": true
|
||||||
},
|
},
|
||||||
"include": ["./*.ts"]
|
"include": ["src/**/*.ts", "eslint.config.js"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user