Skip to content

Commit

Permalink
chore(config): consolidate eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
csantiago132 committed Dec 8, 2024
1 parent 50f0990 commit 8f67f12
Show file tree
Hide file tree
Showing 7 changed files with 786 additions and 721 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@
"eslint-plugin-tsdoc": "^0.2.17",
"eslint-plugin-unicorn": "^51.0.1",
"eslint-plugin-vitest": "^0.5.4",
"globals": "^15.13.0",
"jsdom": "^25.0.1",
"lint-staged": "^15.2.10",
"prettier-plugin-packagejson": "^2.5.6",
"prettier-plugin-sort-imports": "^1.8.6",
"prettier-plugin-tailwindcss": "^0.6.9",
"semantic-release-github-pullrequest": "^1.3.0",
"typescript-eslint": "^8.17.0",
"url-join": "^4.0.1",
"vite-plugin-dts": "^4.3.0",
"vite-tsconfig-paths": "^5.1.3",
Expand Down
1,412 changes: 729 additions & 683 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

33 changes: 17 additions & 16 deletions src/eslint/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,34 @@
* Explore our open-source projects: {@link https://github.com/kurocado-studio}
*/
import babelParser from '@babel/eslint-parser';
import tsRecommended from '@typescript-eslint/eslint-plugin';
import typescriptParser from '@typescript-eslint/parser';
import prettierConfig from 'eslint-config-prettier';
import eslintPluginImport from 'eslint-plugin-import';
import tsdocRecommended from 'eslint-plugin-tsdoc';
import unicornRecommended from 'eslint-plugin-unicorn';
import vitestRecommended from 'eslint-plugin-vitest';
import tsRecommended from 'typescript-eslint';

import { base } from './rules/base/index.js';
import { typescriptEslintConfig } from './rules/typescript/index.js';

const SPEC_PREFIX = 'spec';
const TEST_PREFIX = 'test';
export const JS_EXTENSIONS_PREFIX = '{js,cjs,jsx,mjsx}';
export const TS_EXTENSIONS_PREFIX = '{ts,tsx,mtsx}';
export const SPEC_PREFIX = 'spec';
export const TEST_PREFIX = 'test';

export const sharedEslintConfig = {
ECMA_VERSION: 2021,
JAVASCRIPT_FILES: ['*.js?(x)', '*.mjs'],
JAVASCRIPT_FILES: [`**/*.${JS_EXTENSIONS_PREFIX}`],
JAVASCRIPT_TEST_FILES: [
`*.${TEST_PREFIX}.js?(x)`,
`*.${SPEC_PREFIX}.js?(x)`,
`*.${TEST_PREFIX}.mjs?(x)`,
`*.${SPEC_PREFIX}.mjs?(x)`,
`**/*.${TEST_PREFIX}.${JS_EXTENSIONS_PREFIX}`,
`**/*.${SPEC_PREFIX}.${JS_EXTENSIONS_PREFIX}`,
],
TYPESCRIPT_FILES: [`**/*.${TS_EXTENSIONS_PREFIX}`],
TYPESCRIPT_TEST_FILES: [
`**/*.${TEST_PREFIX}.${TS_EXTENSIONS_PREFIX}`,
`**/*.${SPEC_PREFIX}.${TS_EXTENSIONS_PREFIX}`,
],
TYPESCRIPT_FILES: ['*.ts?(x)'],
TYPESCRIPT_TEST_FILES: [`*.${TEST_PREFIX}.ts?(x)`, `*.${SPEC_PREFIX}.ts?(x)`],
};

export const typescriptLanguageOptions = {
Expand Down Expand Up @@ -67,12 +70,9 @@ export const javascriptLanguageOptions = {
},
};

export const tsconfigRootDir = process.cwd();

export const typescriptLanguageRootConfig = {
...typescriptLanguageOptions,
plugins: {
'@typescript-eslint': tsRecommended,
import: eslintPluginImport,
prettierConfig,
tsdoc: tsdocRecommended,
Expand All @@ -81,6 +81,7 @@ export const typescriptLanguageRootConfig = {
},
rules: {
...base.rules,
...tsRecommended.rules,
...eslintPluginImport.configs.recommended.rules,
...eslintPluginImport.configs.typescript.rules,
...typescriptEslintConfig.rules,
Expand All @@ -93,14 +94,14 @@ export const typescriptLanguageRootConfig = {
export const javascriptLanguageRootConfig = {
...javascriptLanguageOptions,
plugins: {
'@typescript-eslint': tsRecommended,
import: eslintPluginImport,
prettierConfig,
prettier: prettierConfig,
tsdoc: tsdocRecommended,
unicorn: unicornRecommended,
vitest: vitestRecommended,
},
rules: {
'@typescript-eslint/no-var-requires': 'off',
...base.rules,
...eslintPluginImport.configs.recommended.rules,
},
};
19 changes: 17 additions & 2 deletions src/eslint/eslint.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
*/
import eslintPluginImport from 'eslint-plugin-import';
import vitestRecommended from 'eslint-plugin-vitest';
import globals from 'globals';

import {
JS_EXTENSIONS_PREFIX,
TS_EXTENSIONS_PREFIX,
javascriptLanguageRootConfig,
sharedEslintConfig,
typescriptLanguageRootConfig,
Expand Down Expand Up @@ -39,11 +42,23 @@ export const eslintBaseConfig = [
},
},
{
files: ['vitest.web.ts', 'vitest.node.ts'],
files: [`vite.*.${TS_EXTENSIONS_PREFIX}`],
rules: {
'import/no-cycle': 'off',
},
},
{
files: [`**/*.${JS_EXTENSIONS_PREFIX}`, `**/*.${TS_EXTENSIONS_PREFIX}`],
languageOptions: {
globals: globals.node,
},
},
{
files: ['src/eslint/constants.js'],
rules: {
'import/no-unresolved': 'off',
},
},
{
files: [
'.commitlintrc.js',
Expand All @@ -56,6 +71,6 @@ export const eslintBaseConfig = [
},
},
{
ignores: ['dist/*', '**/*.d.ts', 'node_modules', '**/temp.js', 'config/*'],
ignores: ['**/*.d.ts', 'dist/*', 'build/*', 'node_modules'],
},
];
13 changes: 5 additions & 8 deletions src/eslint/eslint.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@
*
* Explore our open-source projects: {@link https://github.com/kurocado-studio}
*/
import babelParser from '@babel/eslint-parser';
import globals from 'globals';

import {
javascriptLanguageOptions,
typescriptLanguageRootConfig,
} from './constants.js';
import { typescriptLanguageRootConfig } from './constants.js';
import { eslintBaseConfig } from './eslint.base.js';

export const eslintBrowserConfig = [
...eslintBaseConfig,
{
...typescriptLanguageRootConfig,
rules: {
...typescriptLanguageRootConfig.rules,
'import/no-cycle': 'off',
languageOptions: {
globals: globals.browser,
},
rules: typescriptLanguageRootConfig.rules,
settings: {
'import/resolver': {
alias: {
Expand Down
11 changes: 1 addition & 10 deletions src/eslint/eslint.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,4 @@
*/
import { eslintBaseConfig } from './eslint.base.js';

export const eslintNodeConfig = [
...eslintBaseConfig,
{
languageOptions: {
globals: {
node: true,
},
},
},
];
export const eslintNodeConfig = eslintBaseConfig;
17 changes: 15 additions & 2 deletions src/eslint/eslint.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,30 @@
import jsxA11yRecommended from 'eslint-plugin-jsx-a11y';
import reactRecommended from 'eslint-plugin-react';
import reactHooksRecommended from 'eslint-plugin-react-hooks';
import globals from 'globals';

import { TS_EXTENSIONS_PREFIX } from './constants.js';
import { reactEslintConfig } from './rules/react/index.js';

export const eslintReactConfig = [
{
files: [`**/*.${TS_EXTENSIONS_PREFIX}`],
...reactRecommended.configs.flat.recommended,
languageOptions: {
...reactRecommended.configs.flat.recommended.languageOptions,
globals: {
...globals.serviceworker,
...globals.browser,
},
},
plugins: {
'jsx-a11y': jsxA11yRecommended,
react: reactRecommended,
'react-hooks': reactHooksRecommended,
},
rules: reactEslintConfig.rules,
rules: {
...reactEslintConfig.rules,
...reactRecommended.configs.flat.recommended.rules,
},
settings: {
react: {
version: 'detect',
Expand Down

0 comments on commit 8f67f12

Please sign in to comment.