Skip to content

Commit

Permalink
style: reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
exuanbo committed Oct 14, 2024
1 parent 6d6614f commit 3062f47
Show file tree
Hide file tree
Showing 17 changed files with 411 additions and 463 deletions.
155 changes: 55 additions & 100 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// @ts-check

/** @import { Linter } from 'eslint' */

import eslint from '@eslint/js'
import pluginStylistic from '@stylistic/eslint-plugin'
import pluginSimpleImportSort from 'eslint-plugin-simple-import-sort'
import globals from 'globals'
import tseslint from 'typescript-eslint'
import eslint from "@eslint/js";
import pluginStylistic from "@stylistic/eslint-plugin";
import pluginSimpleImportSort from "eslint-plugin-simple-import-sort";
import globals from "globals";
import tseslint from "typescript-eslint";

export default tseslint.config(
{
name: 'exuanbo/languages',
name: "exuanbo/languages",
languageOptions: {
ecmaVersion: 2022,
globals: {
Expand All @@ -21,132 +19,89 @@ export default tseslint.config(
},
},
{
name: 'exuanbo/ignores',
ignores: ['.yarn', 'coverage', 'dist', 'docs'],
name: "exuanbo/ignores",
ignores: [".yarn", "coverage", "dist", "docs"],
},
{
name: 'exuanbo/files',
files: ['**/*.?(c|m){j,t}s'],
name: "exuanbo/files",
files: ["**/*.?(c|m){j,t}s"],
},
{
name: 'exuanbo/eslint',
name: "exuanbo/eslint",
extends: [
{
name: 'eslint/recommended',
name: "eslint/recommended",
...eslint.configs.recommended,
},
],
rules: {
'no-param-reassign': 'error',
"no-param-reassign": "error",
},
},
{
name: 'exuanbo/typescript',
name: "exuanbo/typescript",
extends: tseslint.configs.recommendedTypeChecked,
languageOptions: {
parserOptions: {
projectService: {
allowDefaultProject: ['eslint.config.mjs'],
allowDefaultProject: ["eslint.config.mjs"],
},
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': ['error', {
fixStyle: 'inline-type-imports',
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/consistent-type-imports": ["error", {
fixStyle: "inline-type-imports",
}],
'@typescript-eslint/no-import-type-side-effects': 'error',
'@typescript-eslint/no-unused-expressions': ['error', {
"@typescript-eslint/no-import-type-side-effects": "error",
"@typescript-eslint/no-unused-expressions": ["error", {
allowShortCircuit: true,
}],
'@typescript-eslint/no-unused-vars': ['error', {
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
"@typescript-eslint/no-unused-vars": ["error", {
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
}],
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
'@typescript-eslint/no-unsafe-function-type': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/unbound-method': 'off',
"@typescript-eslint/no-empty-object-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-enum-comparison": "off",
"@typescript-eslint/no-unsafe-function-type": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/unbound-method": "off",
},
},
{
name: 'simple-import-sort',
name: "simple-import-sort/all",
plugins: {
'simple-import-sort': pluginSimpleImportSort,
"simple-import-sort": pluginSimpleImportSort,
},
rules: {
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
},
},
{
name: 'exuanbo/stylistic',
plugins: {
'@stylistic': pluginStylistic,
name: "exuanbo/stylistic",
extends: [
{
name: "stylistic/recommended",
...pluginStylistic.configs.customize({
flat: true,
arrowParens: true,
blockSpacing: false,
jsx: false,
quotes: "double",
semi: true,
}),
},
],
rules: {
"@stylistic/object-curly-spacing": ["error", "never"],
},
rules: extendRules(pluginStylistic.configs['recommended-flat'].rules, {
'@stylistic/arrow-parens': ['error', 'always'],
'@stylistic/block-spacing': ['error', 'never'],
'@stylistic/indent': ['error', 2, {
SwitchCase: 0,
}],
'@stylistic/object-curly-spacing': ['error', 'never'],
'@stylistic/quotes': ['error', 'single', {
avoidEscape: true,
allowTemplateLiterals: true,
}],
}),
},
)

/**
* @param {Partial<Linter.RulesRecord> | undefined} rules
* @param {Linter.RulesRecord} record
* @returns {Partial<Linter.RulesRecord>}
*/
function extendRules(rules = {}, record) {
return Object.entries(record).reduce(
(extendedRules, [name, entry]) =>
Object.assign(extendedRules, extendRule(name, entry)),
rules,
)

/**
* @param {string} name
* @param {Linter.RuleEntry} entry
* @returns {Linter.RulesRecord}
*/
function extendRule(name, entry) {
if (!Array.isArray(entry)) {
return {[name]: entry}
}
const defaultEntry = rules[name]
if (!Array.isArray(defaultEntry)) {
return {[name]: entry}
}
const [, ...defaultOptions] = defaultEntry
const [level, ...options] = entry
const extendedOptions = options.map((option, i) => {
if (typeof option !== 'object') {
return option
}
const defaultOption = defaultOptions[i]
if (typeof defaultOption !== 'object') {
return option
}
return {
...defaultOption,
...option,
}
})
return {[name]: [level, ...extendedOptions]}
}
}
);
Loading

0 comments on commit 3062f47

Please sign in to comment.