Skip to content

Commit

Permalink
!WIP! start migration to flat config
Browse files Browse the repository at this point in the history
  • Loading branch information
darthmaim committed Dec 6, 2024
1 parent c206782 commit a18945c
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 264 deletions.
14 changes: 2 additions & 12 deletions apps/legacy-importer/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import js from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';
import config from '@gw2treasures/eslint-config';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});
export default [...compat.extends('@gw2treasures/eslint-config')];
export default config;
14 changes: 2 additions & 12 deletions apps/worker/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import js from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';
import config from '@gw2treasures/eslint-config';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});
export default [...compat.extends('@gw2treasures/eslint-config')];
export default config;
97 changes: 0 additions & 97 deletions packages/eslint-config/configs/index.json

This file was deleted.

85 changes: 85 additions & 0 deletions packages/eslint-config/configs/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import js from "@eslint/js";
import ts from 'typescript-eslint';
import importPlugin from 'eslint-plugin-import';
import stylistic from '@stylistic/eslint-plugin'

export default ts.config(
js.configs.recommended,
ts.configs.recommended,
importPlugin.flatConfigs.recommended,
importPlugin.flatConfigs.typescript,
{
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: {
'@stylistic': stylistic
},
rules: {
// `"foo"` → `'foo'`
"@stylistic/quotes": ["warn", "single"],

// `a => a` → `(a) => a`
"@stylistic/arrow-parens": "warn",

// `(a)=>a` → `(a) => a`
"@stylistic/arrow-spacing": "warn",

// `foo( bar )` → `foo(bar)`
"@stylistic/space-in-parens": "warn",

// disallows multipe spaces
"@stylistic/no-multi-spaces": "warn",

// disallow multiple empty lines
"@stylistic/no-multiple-empty-lines": "warn",

// only 1 property per line for objects (enforced only for > 3 properties or multiline values)
"@stylistic/object-curly-newline": ["warn", { "multiline": true, "consistent": true }],

// `{foo: bar}` → `{ foo: bar }`
"@stylistic/object-curly-spacing": ["warn", "always", { "objectsInObjects": false }],

// `{ foo:bar }` → `{ foo: bar }`
"@stylistic/key-spacing": "warn",

// `{ x: x }` → `{ x }`
"object-shorthand": "warn",

// allows (but does not require) dangling commas in multiline
"@stylistic/comma-dangle": ["warn", "only-multiline"],

// `foo(bar,baz)` → `foo(bar, baz)`
"@stylistic/comma-spacing": "warn",

// `1+1` → `1 + 1`
"@stylistic/space-infix-ops": "warn",

// require semicolon
"@stylistic/semi": "warn",

// no unnecessary semicolon
"@stylistic/no-extra-semi": ["warn"],

// disallows async functions not using await
"require-await": "warn",

// require dependencies to be in package.json
"import/no-extraneous-dependencies": "error",

// disable import/no-unresolved, ts is already handling this
"import/no-unresolved": "off",

// `const foo:Bar` → `const foo: Bar`
"@stylistic/type-annotation-spacing": "warn",

// `class foo_bar` → `class FooBar`
"@typescript-eslint/naming-convention": [
"warn",
{ "selector": "default", "format": null },
{ "selector": "typeLike", "format": ["PascalCase"] }
]
}
}
);
75 changes: 0 additions & 75 deletions packages/eslint-config/configs/react.json

This file was deleted.

73 changes: 73 additions & 0 deletions packages/eslint-config/configs/react.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import ts from 'typescript-eslint';
import react from 'eslint-plugin-react';
import config from './index.mjs';

export default ts.config(
react.configs.flat.recommended,
react.configs.flat['jsx-runtime'],
config,
{
rules: {
// `<C foo='bar'>` → `<C foo="bar">`
"@stylistic/jsx-quotes": ["warn", "prefer-double"],

// `< C / >` → `<C/>`
"@stylistic/jsx-tag-spacing": ["warn", {
"closingSlash": "never",
"beforeSelfClosing": "never",
"afterOpening": "never",
"beforeClosing": "never"
}],

// `<C prop={'test'}/>` → `<C prop="test"/>`
"@stylistic/jsx-curly-brace-presence": ["warn", "never"],

// add parens around jsx
"@stylistic/jsx-wrap-multilines": ["warn", {
"declaration": "parens-new-line",
"assignment": "parens-new-line",
"return": "parens-new-line",
"arrow": "parens-new-line",
"condition": "parens-new-line",
"logical": "parens-new-line",
"prop": "parens-new-line"
}],

// multiline closing bracket location
"@stylistic/jsx-closing-bracket-location": ["warn", {
"nonEmpty": "line-aligned",
"selfClosing": "after-props"
}],

// indent jsx with 2 spaces
"@stylistic/jsx-indent": ["warn", 2, { "checkAttributes": true, "indentLogicalExpressions": true }],

// indent props with 2 spaces
"@stylistic/jsx-indent-props": ["warn", 2],

// disallows using the array index as key
"react/no-array-index-key": "warn",

// `<Foo></Foo>` → `<Foo/>`
"react/self-closing-comp": "warn",

// `<Foo bar={true}>` → `<Foo bar/>`
"react/jsx-boolean-value": "warn",

// align the closing JSX tag with the opening tag
"@stylistic/jsx-closing-tag-location": "warn",

// `<React.Fragment>` → `<>`
"react/jsx-fragments": "warn",

// require key
"react/jsx-key": ["warn", { "checkFragmentShorthand": true }],

// prevent multiple spaces in jsx
"@stylistic/jsx-props-no-multi-spaces": "warn",

// `<Foo bar={ baz }>` → `<Foo bar={baz}/>`
"@stylistic/jsx-curly-spacing": "warn",
}
}
);
10 changes: 5 additions & 5 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "0.0.6",
"description": "ESLint config for gw2treasures",
"exports": {
".": "./configs/index.json",
"./react": "./configs/react.json"
".": "./configs/index.mjs",
"./react": "./configs/react.mjs"
},
"scripts": {
"publish-package": "gw2treasures-publish-package"
Expand All @@ -28,11 +28,11 @@
},
"homepage": "https://github.com/GW2Treasures/gw2treasures.com#readme",
"dependencies": {
"@eslint/js": "9.16.0",
"@stylistic/eslint-plugin": "2.11.0",
"@typescript-eslint/eslint-plugin": "8.17.0",
"@typescript-eslint/parser": "8.17.0",
"eslint-plugin-import": "2.31.0",
"eslint-plugin-react": "7.37.2"
"eslint-plugin-react": "7.37.2",
"typescript-eslint": "8.17.0"
},
"peerDependencies": {
"eslint": "^9.16.0"
Expand Down
Loading

0 comments on commit a18945c

Please sign in to comment.