Skip to content

Commit

Permalink
Disable Prettier in favor of Biome
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer committed Jun 22, 2024
1 parent 8d08964 commit be0a159
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 74 deletions.
4 changes: 2 additions & 2 deletions .huskyrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
// run their own binaries.
module.exports = {
hooks: {
'pre-commit': 'lint-staged'
}
'pre-commit': 'lint-staged',
},
};
2 changes: 0 additions & 2 deletions .prettierignore

This file was deleted.

13 changes: 13 additions & 0 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"useIgnoreFile": true
},
"organizeImports": { "enabled": false },
"formatter": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"style": {
"noDefaultExport": "error",
Expand All @@ -25,6 +29,15 @@
}
},
"overrides": [
{
// Workaround to match the format that npm uses
"include": ["package.json"],
"json": {
"formatter": {
"lineWidth": 1
}
}
},
{
"include": ["src/lib/logger.ts"],
"linter": {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"start": "npm run dev",
"cleanup": "rimraf ./dist && mkdir dist",
"prelint": "npm run build",
"lint": "biome lint && eslint src --ext .js,.jsx,.json,.ts,.tsx",
"lint:fix": "biome lint --write && eslint src --ext .js,.jsx,.json,.ts,.tsx --fix",
"lint": "biome check && eslint src --ext .js,.jsx,.json,.ts,.tsx",
"lint:fix": "biome check --write && eslint src --ext .js,.jsx,.json,.ts,.tsx --fix",
"lint:ci": "biome ci && eslint src --ext .js,.jsx,.json,.ts,.tsx",
"test": "vitest",
"test:ci": "vitest run --coverage",
Expand Down
16 changes: 0 additions & 16 deletions prettier.config.js

This file was deleted.

42 changes: 1 addition & 41 deletions src/configs/biome/biome.jsonc
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.2/schema.json",
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"ignore": ["dist/**"]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"a11y": {
Expand Down Expand Up @@ -60,43 +58,5 @@
"quoteProperties": "preserve",
"quoteStyle": "single"
}
},
"overrides": [
{
// Workaround to match the format that npm uses
"include": ["package.json"],
"json": {
"formatter": {
"lineWidth": 1
}
}
},
{
"include": ["*.css"],
"css": {
"formatter": {
"enabled": true,
"indentStyle": "space",
"quoteStyle": "double"
},
"linter": {
"enabled": true
}
}
},
{
"include": ["*.module.css"],
"css": { "parser": { "cssModules": true } }
},
{
"include": ["**/*spec.*", "**/setupTests.*", "**/test-utils.*"],
"linter": {
"rules": {
"suspicious": {
"noGlobalAssign": "off"
}
}
}
}
]
}
}
224 changes: 213 additions & 11 deletions src/configs/eslint/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ const sharedOverrides = [

const base = {
root: true,
// TODO: Remove prettier
extends: ['eslint:recommended', 'airbnb-base', 'plugin:prettier/recommended'],
extends: ['eslint:recommended', 'airbnb-base'],
parser: '@babel/eslint-parser',
parserOptions: {
sourceType: 'module',
Expand All @@ -147,14 +146,6 @@ const base = {
},
rules: sharedRules,
overrides: [
// TODO: Remove json handling
{
files: ['**/*.json'],
extends: ['plugin:json/recommended'],
rules: {
'notice/notice': 'off',
},
},
{
files: NODE_FILES,
rules: {
Expand All @@ -164,6 +155,217 @@ const base = {
],
};

function customizeFormatter(useBiome: boolean) {
return (config: ESLintConfig): ESLintConfig => {
if (useBiome) {
return customizeConfig(config, {
// eslint-config-prettier disables ESLint's stylistic rules which are also covered by Biome
extends: ['prettier'],
rules: {
// Covered by Biome:
'constructor-super': 'off',
'curly': 'off',
'default-case': 'off',
'default-case-last': 'off',
'default-param-last': 'off',
'dot-notation': 'off',
'eqeqeq': 'off',
'for-direction': 'off',
'getter-return': 'off',
'no-array-constructor': 'off',
'no-async-promise-executor': 'off',
'no-case-declarations': 'off',
'no-class-assign': 'off',
'no-compare-neg-zero': 'off',
'no-cond-assign': 'off',
'no-console': 'off',
'no-const-assign': 'off',
'no-constant-condition': 'off',
'no-constructor-return': 'off',
'no-control-regex': 'off',
'no-debugger': 'off',
'no-dupe-args': 'off',
'no-dupe-class-members': 'off',
'no-dupe-else-if': 'off',
'no-dupe-keys': 'off',
'no-duplicate-case': 'off',
'no-else-return': 'off',
'no-empty': 'off',
'no-empty-character-class': 'off',
'no-empty-function': 'off',
'no-empty-pattern': 'off',
'no-empty-static-block': 'off',
'no-eval': 'off',
'no-ex-assign': 'off',
'no-extra-boolean-cast': 'off',
'no-extra-label': 'off',
'no-fallthrough': 'off',
'no-func-assign': 'off',
'no-global-assign': 'off',
'no-import-assign': 'off',
'no-inner-declarations': 'off',
'no-label-var': 'off',
'no-labels': 'off',
'no-lone-blocks': 'off',
'no-lonely-if': 'off',
'no-loss-of-precision': 'off',
'no-misleading-character-class': 'off',
'no-negated-condition': 'off',
'no-new-native-nonconstructor': 'off',
'no-new-symbol': 'off',
'no-new-wrappers': 'off',
'no-nonoctal-decimal-escape': 'off',
'no-obj-calls': 'off',
'no-param-reassign': 'off',
'no-prototype-builtins': 'off',
'no-redeclare': 'off',
'no-regex-spaces': 'off',
'no-restricted-globals': 'off',
'no-restricted-imports': 'off',
'no-self-assign': 'off',
'no-self-compare': 'off',
'no-sequences': 'off',
'no-setter-return': 'off',
'no-shadow-restricted-names': 'off',
'no-sparse-array': 'off',
'no-this-before-super': 'off',
'no-throw-literal': 'off',
'no-undef': 'off',
'no-undef-init': 'off',
'no-unneeded-ternary': 'off',
'no-unreachable': 'off',
'no-unsafe-finally': 'off',
'no-unsafe-negation': 'off',
'no-unsafe-optional-chaining': 'off',
'no-unused-labels': 'off',
'no-unused-private-class-members': 'off',
'no-unused-vars': 'off',
'no-use-before-define': 'off',
'no-useless-catch': 'off',
'no-useless-concat': 'off',
'no-useless-constructor': 'off',
'no-useless-rename': 'off',
'no-var': 'off',
'no-void': 'off',
'no-with': 'off',
'one-var': 'off',
'operator-assignment': 'off',
'prefer-arrow-callback': 'off',
'prefer-const': 'off',
'prefer-exponentiation-operator': 'off',
'prefer-numeric-literals': 'off',
'prefer-regex-literals': 'off',
'prefer-rest-params': 'off',
'prefer-template': 'off',
'require-await': 'off',
'require-yield': 'off',
'use-isnan': 'off',
'valid-typeof': 'off',
'yoda': 'off',
'jsx-ally/alt-text': 'off',
'jsx-ally/anchor-has-content': 'off',
'jsx-ally/anchor-is-valid': 'off',
'jsx-ally/aria-activedescendant-has-tabindex': 'off',
'jsx-ally/aria-props': 'off',
'jsx-ally/aria-proptypes': 'off',
'jsx-ally/aria-role': 'off',
'jsx-ally/aria-unsupported-elements': 'off',
'jsx-ally/autocomplete-valid': 'off',
'jsx-ally/click-events-have-key-events': 'off',
'jsx-ally/heading-has-content': 'off',
'jsx-ally/html-has-lang': 'off',
'jsx-ally/iframe-has-title': 'off',
'jsx-ally/img-redundant-alt': 'off',
'jsx-ally/interactive-support-focus': 'off',
'jsx-ally/label-has-associated-control': 'off',
'jsx-ally/lang': 'off',
'jsx-ally/media-has-caption': 'off',
'jsx-ally/mouse-events-have-key-events': 'off',
'jsx-ally/no-access-key': 'off',
'jsx-ally/no-aria-hidden-on-focusable': 'off',
'jsx-ally/no-autofocus': 'off',
'jsx-ally/no-distracting-elements': 'off',
'jsx-ally/no-interactive-element-to-noninteractive-role': 'off',
'jsx-ally/no-noninteractive-element-to-interactive-role': 'off',
'jsx-ally/no-noninteractive-tabindex': 'off',
'jsx-ally/no-redundant-roles': 'off',
'jsx-ally/prefer-tag-over-role': 'off',
'jsx-ally/role-has-required-aria-props': 'off',
'jsx-ally/scope': 'off',
'jsx-ally/tabindex-no-positive': 'off',
'react/button-has-type': 'off',
'react/jsx-boolean-value': 'off',
'react/jsx-fragments': 'off',
'react/jsx-key': 'off',
'react/jsx-no-comment-textnodes': 'off',
'react/jsx-no-duplicate-props': 'off',
'react/jsx-no-target-blank': 'off',
'react/jsx-no-useless-fragment': 'off',
'react/no-array-index-key': 'off',
'react/no-children-prop': 'off',
'react/no-danger': 'off',
'react/no-danger-with-children': 'off',
'react/void-dom-elements-no-children': 'off',
'react-hooks/exhaustive-deps': 'off',
'react-hooks/rules-of-hooks': 'off',
'@typescript-eslint/adjacent-overload-signatures': 'off',
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/consistent-type-exports': 'off',
'@typescript-eslint/consistent-type-imports': 'off',
'@typescript-eslint/default-param-last': 'off',
'@typescript-eslint/dot-notation': 'off',
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/no-dupe-class-members': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-extra-non-null-assertion': 'off',
'@typescript-eslint/no-extraneous-class': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-invalid-void-type': 'off',
'@typescript-eslint/no-loss-of-precision': 'off',
'@typescript-eslint/no-misused-new': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-redeclare': 'off',
'@typescript-eslint/no-restricted-imports': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-throw-literal': 'off',
'@typescript-eslint/no-unnecessary-type-constraint': 'off',
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-useless-constructor': 'off',
'@typescript-eslint/no-useless-empty-export': 'off',
'@typescript-eslint/only-throw-error': 'off',
'@typescript-eslint/parameter-properties': 'off',
'@typescript-eslint/prefer-as-const': 'off',
'@typescript-eslint/prefer-enum-initializers': 'off',
'@typescript-eslint/prefer-for-of': 'off',
'@typescript-eslint/prefer-function-type': 'off',
'@typescript-eslint/prefer-literal-enum-member': 'off',
'@typescript-eslint/prefer-namespace-keyword': 'off',
'@typescript-eslint/prefer-optional-chain': 'off',
'@typescript-eslint/require-await': 'off',
},
});
}
return customizeConfig(config, {
extends: ['plugin:prettier/recommended'],
overrides: [
{
files: ['**/*.json'],
extends: ['plugin:json/recommended'],
rules: {
'notice/notice': 'off',
},
},
],
});
};
}

function customizeLanguage(language: Language) {
const languageMap = {
[Language.JAVASCRIPT]: {
Expand Down Expand Up @@ -401,7 +603,6 @@ function customizeFramework(frameworks: Framework[]) {
logger.warn(
`The '${Framework.NEXT_JS}' framework includes React-specific rules. Please remove the '${Framework.REACT}' framework to avoid conflicts.`,
);
// eslint-disable-next-line no-param-reassign
// biome-ignore lint/style/noParameterAssign:
frameworks = frameworks.filter(
(framework) => framework !== Framework.REACT,
Expand Down Expand Up @@ -546,6 +747,7 @@ export function createConfig(overrides: ESLintConfig = {}): ESLintConfig {
const options = getOptions();

return flow(
customizeFormatter(options.useBiome),
customizeLanguage(options.language),
customizeEnvironments(options.environments),
customizeFramework(options.frameworks),
Expand Down
1 change: 1 addition & 0 deletions src/lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export function getOptions(): Required<Options> {
plugins: pick(config.plugins, detectPlugins),
openSource: pick(config.openSource, detectOpenSource),
workspaces: packageJson.workspaces || null,
useBiome: hasDependency(packageJson, '@biomejs/biome'),
};
}

Expand Down
Loading

0 comments on commit be0a159

Please sign in to comment.