Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eslint-plugin-compat #134

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Ultracite is a robust linting preset for modern TypeScript apps. It's comprised

### ESLint

Ultracite uses [ESLint](https://eslint.org/) to enforce code quality and type safety. It includes a wide range of rules to ensure your code is consistent and error-free. Ultracite combines with pre-defined rulesets for ESLint, as well as the following plugins: [Import](https://www.npmjs.com/package/eslint-plugin-import), [jsx-a11y](https://www.npmjs.com/package/eslint-plugin-jsx-a11y), [React](https://www.npmjs.com/package/eslint-plugin-react), [React Hooks](https://www.npmjs.com/package/eslint-plugin-react-hooks), [jest](https://www.npmjs.com/package/eslint-plugin-jest), [promise](https://www.npmjs.com/package/eslint-plugin-promise), [n](https://www.npmjs.com/package/eslint-plugin-n), [Typescript](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin), [Prettier](https://www.npmjs.com/package/eslint-plugin-prettier), [Next.js](https://nextjs.org/docs/basic-features/eslint#eslint-plugin), [Cypress](https://www.npmjs.com/package/eslint-plugin-cypress), [HTML](https://www.npmjs.com/package/eslint-plugin-html) and [SonarJS](https://www.npmjs.com/package/eslint-plugin-sonarjs).
Ultracite uses [ESLint](https://eslint.org/) to enforce code quality and type safety. It includes a wide range of rules to ensure your code is consistent and error-free. Ultracite combines with pre-defined rulesets for ESLint, as well as the following plugins: [Import](https://www.npmjs.com/package/eslint-plugin-import), [jsx-a11y](https://www.npmjs.com/package/eslint-plugin-jsx-a11y), [React](https://www.npmjs.com/package/eslint-plugin-react), [React Hooks](https://www.npmjs.com/package/eslint-plugin-react-hooks), [jest](https://www.npmjs.com/package/eslint-plugin-jest), [promise](https://www.npmjs.com/package/eslint-plugin-promise), [n](https://www.npmjs.com/package/eslint-plugin-n), [Typescript](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin), [Prettier](https://www.npmjs.com/package/eslint-plugin-prettier), [Next.js](https://nextjs.org/docs/basic-features/eslint#eslint-plugin), [Cypress](https://www.npmjs.com/package/eslint-plugin-cypress), [HTML](https://www.npmjs.com/package/eslint-plugin-html), [SonarJS](https://www.npmjs.com/package/eslint-plugin-sonarjs) and [Compat](https://www.npmjs.com/package/eslint-plugin-compat).

### Prettier

Expand Down Expand Up @@ -137,5 +137,4 @@ If you see any errors, it could be related to peer dependencies or changes in de
- https://github.com/ota-meshi/eslint-plugin-yml
- https://github.com/mdx-js/eslint-mdx/tree/master/packages/eslint-plugin-mdx
- https://github.com/eslint/eslint-plugin-markdown
- https://github.com/amilajack/eslint-plugin-compat
- https://github.com/sindresorhus/eslint-plugin-unicorn
189 changes: 1 addition & 188 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,188 +1 @@
/* eslint-disable n/no-unpublished-import, n/no-extraneous-import, import/no-extraneous-dependencies, id-length */

import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import typescript from '@typescript-eslint/eslint-plugin';
import jsxA11y from 'eslint-plugin-jsx-a11y';
import * as importPlugin from 'eslint-plugin-import';
import jest from 'eslint-plugin-jest';
import promise from 'eslint-plugin-promise';
import n from 'eslint-plugin-n';
import next from '@next/eslint-plugin-next';
import globals from 'globals';
import prettier from 'eslint-plugin-prettier';
import cypress from 'eslint-plugin-cypress';
import storybook from 'eslint-plugin-storybook';
import unusedImports from 'eslint-plugin-unused-imports';
// import tailwindcss from 'eslint-plugin-tailwindcss';
import * as importTypescriptResolver from 'eslint-import-resolver-typescript';
import html from 'eslint-plugin-html';

import eslintPrettier from 'eslint-config-prettier';
import * as typescriptParser from '@typescript-eslint/parser';
import sonarjs from 'eslint-plugin-sonarjs';

import eslintRules from './rules/eslint.mjs';
import reactRules from './rules/react.mjs';
import reactHooksRules from './rules/reactHooks.mjs';
import typescriptRules from './rules/typescript.mjs';
import jsxA11yRules from './rules/jsx-a11y.mjs';
import importRules from './rules/import.mjs';
import jestRules from './rules/jest.mjs';
import promiseRules from './rules/promise.mjs';
import nRules from './rules/n.mjs';
import nextRules from './rules/next.mjs';
import prettierRules from './rules/prettier.mjs';
import eslintTypescriptRules from './rules/eslint-typescript.mjs';
import cypressRules from './rules/cypress.mjs';
import storybookRules from './rules/storybook.mjs';
// import tailwindcssRules from './rules/tailwindcss.mjs';
import unusedImportsRules from './rules/unused-imports.mjs';
import sonarjsRules from './rules/sonarjs.mjs';

// Patch AudioWorkletGlobalScope
const browserGlobals = { ...globals.browser };
delete browserGlobals['AudioWorkletGlobalScope '];

const config = [
importPlugin.configs.typescript,
{
languageOptions: {
sourceType: 'module',
globals: {
...browserGlobals,
...globals.node,
},
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
},
files: [
'**/*.js',
'**/*.jsx',
'**/*.ts',
'**/*.tsx',
'**/*.json',
'**/*.mjs',
'**/*.cjs',
'**/*.html',
],
plugins: {
prettier,
react,
'react-hooks': reactHooks,
'jsx-a11y': jsxA11y,
import: importPlugin,
promise,
n,
'@next/next': next,
'unused-imports': unusedImports,
// tailwindcss,
sonarjs,
},
rules: {
...eslintRules,
...reactRules,
...reactHooksRules,
...jsxA11yRules,
...importRules,
...promiseRules,
...nRules,
...nextRules,
...prettierRules,
...eslintPrettier.rules,
...unusedImportsRules,
// ...tailwindcssRules,
...sonarjsRules,
},

settings: {
react: {
version: 'detect',
},

// https://github.com/import-js/eslint-plugin-import/issues/2556#issuecomment-1419518561
'import/parsers': {
espree: ['.js', '.cjs', '.mjs', '.jsx', '.ts', '.tsx'],
},
'import/resolver': {
typescript: true,
node: true,
},
},
},
{
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parser: typescriptParser,
parserOptions: {
project: './tsconfig.json',
},
},
plugins: {
'@typescript-eslint': typescript,
'import/typescript': importTypescriptResolver,
},
rules: {
...eslintTypescriptRules,
...typescriptRules,
},
},
{
files: ['**/*.test.js', '**/*.test.jsx', 'tests/**/*.js', 'tests/**/*.jsx'],
languageOptions: {
globals: {
...globals.jest,
},
},
plugins: {
jest,
},
rules: {
...jestRules,
},
},
{
files: ['**/*.cy.js', '**/*.cy.jsx'],
languageOptions: {
globals: {
...globals.cypress,
},
},
plugins: {
cypress,
},
rules: {
...cypressRules,
},
},
{
files: [
'**/*.stories.js',
'**/*.stories.jsx',
'**/*.stories.ts',
'**/*.stories.tsx',
],
plugins: {
storybook,
},
rules: {
...storybookRules,
},
},
{
files: ['**/*.html'],
plugins: {
html,
},
settings: {
'html/javascript-tag-names': ['script', 'Script'],
},
},
];

export default config;
export { default } from './dist/eslint.config.mjs';
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"browserslist": [
"defaults"
],
"dependencies": {
"@next/eslint-plugin-next": "^14.2.3",
"@typescript-eslint/eslint-plugin": "^7.11.0",
"@typescript-eslint/parser": "^7.11.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-compat": "^4.2.0",
"eslint-plugin-cypress": "^3.2.0",
"eslint-plugin-html": "^8.1.1",
"eslint-plugin-import": "^2.29.1",
Expand Down
Loading
Loading