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": {
|
||||
"@eslint/js": "^9.39.2",
|
||||
"@stylistic/eslint-plugin": "^5.7.0",
|
||||
"eslint": "^9.39.2",
|
||||
"eslint-plugin-react": "^7.37.5",
|
||||
"eslint-plugin-react-hooks": "^7.0.1",
|
||||
"globals": "^17.0.0",
|
||||
"typescript-eslint": "^8.53.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^9.39.2",
|
||||
"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",
|
||||
"private": true,
|
||||
"description": "Shared ESLint configuration for Probo monorepo",
|
||||
"main": "eslint.config.mjs",
|
||||
"main": "./src/index.ts",
|
||||
"type": "module",
|
||||
"scripts": {},
|
||||
"scripts": {
|
||||
"lint": "eslint src"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@eslint/js": "^9.39.2",
|
||||
"@stylistic/eslint-plugin": "^5.7.0",
|
||||
"eslint": "^9.39.2",
|
||||
"eslint-plugin-react": "^7.37.5",
|
||||
"eslint-plugin-react-hooks": "^7.0.1",
|
||||
"globals": "^17.0.0",
|
||||
"typescript-eslint": "^8.53.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^9.39.2",
|
||||
"typescript": "^5.8.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as js from "@eslint/js";
|
||||
import js from "@eslint/js";
|
||||
|
||||
export const baseConfigs = [
|
||||
{ ignores: ["dist", "node_modules", "**/*.d.ts"] },
|
||||
{ files: ["**/*.js", "**/*.ts", "**/*.tsx"] },
|
||||
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 = {
|
||||
languageOptions: {
|
||||
// Same as the ones we use in our tsconfig compilerOptions.lib for browser
|
||||
ecmaVersion: 2022,
|
||||
globals: {
|
||||
...browser,
|
||||
...es2022,
|
||||
...globals.browser,
|
||||
...globals.es2022,
|
||||
},
|
||||
sourceType: "module",
|
||||
parserOptions: {
|
||||
projectService: true,
|
||||
ecmaFeatures: {
|
||||
impliedStrict: true,
|
||||
},
|
||||
@@ -22,11 +23,12 @@ export const nodeLanguageOptionsConfig = {
|
||||
// Same as the ones we use in our tsconfig compilerOptions.lib for node
|
||||
ecmaVersion: 2023,
|
||||
globals: {
|
||||
...node,
|
||||
...es2023,
|
||||
...globals.node,
|
||||
...globals.es2023,
|
||||
},
|
||||
sourceType: "module",
|
||||
parserOptions: {
|
||||
projectService: true,
|
||||
ecmaFeatures: {
|
||||
impliedStrict: true,
|
||||
},
|
||||
@@ -1,4 +1,5 @@
|
||||
import stylistic from "@stylistic/eslint-plugin";
|
||||
import { type Linter } from "eslint";
|
||||
|
||||
export const stylisticConfigs = [
|
||||
stylistic.configs.customize({
|
||||
@@ -20,5 +21,5 @@ export const stylisticConfigs = [
|
||||
{ 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"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "nodenext",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"moduleDetection": "force",
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
@@ -14,5 +15,5 @@
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["./*.ts"]
|
||||
"include": ["src/**/*.ts", "eslint.config.js"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user