@cutting/oxc-config
v1.2.0
Published
Cutting Oxlint and oxfmt configuration
Downloads
567
Maintainers
Readme
Cutting oxc-config
This package holds the shared Oxlint and oxfmt configs that other packages use.
Installation
pnpm add @cutting/oxc-config -DThe package installs oxlint, oxfmt, eslint-plugin-simple-import-sort, eslint-plugin-sonarjs and eslint-plugin-storybook.
Configuration
Create one oxlint.config.ts in the root of the repo:
import config from '@cutting/oxc-config/react';
export default config;Use @cutting/oxc-config/eslint instead for a repo with no React code.
Create one oxfmt.config.ts in the root of the repo:
import config from '@cutting/oxc-config/oxfmt';
export default config;Oxlint and oxfmt find these files from any folder below the root, so a package needs no config file of its own.
package.json scripts
Add a lint script to each package:
"scripts": {
"lint": "oxlint ./src --fix && oxfmt ./src"
}Format on save in VS Code
Install the Oxc extension (oxc.oxc-vscode), and add this to .vscode/settings.json:
{
"editor.defaultFormatter": "oxc.oxc-vscode",
"editor.formatOnSave": true
}Disable comments
Oxlint obeys oxlint-disable and eslint-disable comments:
// oxlint-disable-next-line typescript/no-explicit-any
/* oxlint-disable eqeqeq */What rules are applied
@cutting/oxc-config/eslint
- The
@typescript-eslint/recommendedrules. curly,eqeqeq,no-var,prefer-constandno-unused-vars(names that start with_are ignored).typescript/explicit-module-boundary-typesandtypescript/consistent-type-imports.import/first,import/newline-after-importandimport/no-duplicates.simple-import-sort/importsandsimple-import-sort/exports, through theeslint-plugin-simple-import-sortJS plugin.no-empty.cutting/no-comments: no comments. Lint directives (eslint-,oxlint-),@ts-expect-error,$ExpectType,$ExpectError,GraphQLtags, triple-slash references and a shebang line are allowed.- The
eslint-plugin-sonarjsrecommended rules, withoutsonarjs/max-lines,sonarjs/no-nested-template-literalsandsonarjs/no-commented-code. Oxlint's built-in rule replaces each sonar rule that has one. These rules are off in*.test.ts,*.test.tsx,*.stories.tsxand__mocks__. max-lines: a*.tsor*.tsxfile has at most 200 lines, not counting blank lines and comments. The rule is off in*.test.ts,*.test.tsx,*.stories.tsxand__mocks__.cutting/no-browser-storage: nolocalStorageorsessionStoragein*.test.tsand*.test.tsx.cutting/no-vi-mock: novi.mockorvi.doMockin*.test.tsand*.test.tsx.vi.fn,vi.spyOnandvi.stubGlobalare allowed.cutting/no-test-code-imports: no import from@storybook/*,storybook/*,msw,vitestor@testing-library/*in a*.tsor*.tsxfile. The rule is off in*.test.ts,*.test.tsx,*.stories.tsx,__mocks__and.storybook.
The cutting/* rules come from a JS plugin inside this package.
@cutting/oxc-config/react
All the rules above, plus:
- The
eslint-plugin-reactrecommended rules. - The
eslint-plugin-jsx-a11yrecommended rules. react/rules-of-hooksandreact/exhaustive-deps, which also checksuseIsomorphicLayoutEffect.cutting/no-react-namespaceandcutting/no-react-namespace-types: noReact.in values or in types. Use named imports.typescript/no-restricted-imports: noJSXimport fromreact.- The
eslint-plugin-storybookrecommended rules, in*.stories.*and*.story.*files and in.storybook/main.*.
@cutting/oxc-config/oxfmt
printWidth: 120,singleQuote: true,semi: true,tabWidth: 2,trailingComma: 'all',sortPackageJson: false.*.jsfiles useprintWidth: 140andtrailingComma: 'none'.
Extending
Spread the config in the root oxlint.config.ts, and add to each field:
import config from '@cutting/oxc-config/react';
export default {
...config,
ignorePatterns: [...config.ignorePatterns, 'tools'],
plugins: [...config.plugins, 'vitest'],
rules: {
...config.rules,
'no-var': 'off',
},
overrides: [
...config.overrides,
{
files: ['**/*.test.ts'],
rules: {
'typescript/no-explicit-any': 'off',
},
},
],
};Spread each field you change. A field without the spread replaces the shared value.
Extend oxfmt.config.ts the same way:
import config from '@cutting/oxc-config/oxfmt';
export default {
...config,
printWidth: 100,
};