diff --git a/.prettierignore b/.prettierignore index 397b4a7..ec7dd18 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1 +1,2 @@ +tests *.log diff --git a/README.md b/README.md index 53d9a0a..022f62f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ESLINT-CONFIG-WELLY -ESlint configuration for my personal [React](https://reactjs.org) projects, which integrates [TypeScript](https://www.typescriptlang.org), [Prettier](https://prettier.io), and [more](#whats-inside). +ESlint configuration for my personal [React](https://reactjs.org) projects, which integrates [TypeScript](https://www.typescriptlang.org), [Compat](https://github.com/amilajack/eslint-plugin-compat), and [more](#whats-inside). [![build status](https://img.shields.io/github/workflow/status/wellyshen/eslint-config-welly/CI?style=flat-square)](https://github.com/wellyshen/eslint-config-welly/actions?query=workflow%3ACI) [![npm version](https://img.shields.io/npm/v/eslint-config-welly?style=flat-square)](https://www.npmjs.com/package/eslint-config-welly) @@ -15,7 +15,7 @@ ESlint configuration for my personal [React](https://reactjs.org) projects, whic ## Installation -This package is distributed via [npm](https://www.npmjs.com/package/eslint-config-welly). It requires [eslint](https://github.com/eslint/eslint), [typescript](https://github.com/microsoft/TypeScript), and [prettier](https://github.com/prettier/prettier). +This package is distributed via [npm](https://www.npmjs.com/package/eslint-config-welly). It requires [eslint](https://github.com/eslint/eslint) and [typescript](https://github.com/microsoft/TypeScript). Install the correct version of each package, which are listed by the command: @@ -32,9 +32,9 @@ npx install-peerdeps --dev eslint-config-welly Or install each package by yourself: ```sh -npm install --save-dev eslint-config-welly eslint@^x.x.x prettier@^x.x.x typescript@^x.x.x +npm install --save-dev eslint-config-welly eslint@^x.x.x typescript@^x.x.x # or -yarn add --dev eslint-config-welly eslint@^x.x.x prettier@^x.x.x typescript@^x.x.x +yarn add --dev eslint-config-welly eslint@^x.x.x typescript@^x.x.x ``` ## Usage @@ -50,6 +50,18 @@ module.exports = { }; ``` +## Eliminate Prettier Conflicts for You + +[Prettier](https://prettier.io) is a great code formatter, I highly recommend you guys give it a try. This package built-ins the [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) for you, all you need to do is setup the [Prettier CLI](https://prettier.io/docs/en/cli.html) to use it. + +```json +// package.json + +"format": "prettier --check ." +// or +"format": "prettier --write ." +``` + ## What's Inside? This configuration contains the following cool packages. @@ -62,7 +74,7 @@ This configuration contains the following cool packages. | [eslint-plugin-react-hooks](https://github.com/facebook/react/tree/master/packages/eslint-plugin-react-hooks) | This ESLint plugin enforces the [Rules of Hooks](https://reactjs.org/docs/hooks-rules.html). | | | [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import) | ESLint plugin with rules that help validate proper imports. | | | [eslint-plugin-jsx-a11y](https://github.com/evcohen/eslint-plugin-jsx-a11y) | Static AST checker for a11y rules on JSX elements. | | -| [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier) | ESLint plugin for Prettier formatting. | | +| [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) | Turns off all rules that are unnecessary or might conflict with Prettier. | Dynamic enabled | | [eslint-plugin-compat](https://github.com/amilajack/eslint-plugin-compat) | Lint the browser compatibility of your code. | | | [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) | ESLint plugin for [Jest](https://jestjs.io). | | | [eslint-plugin-jest-dom](https://github.com/testing-library/eslint-plugin-jest-dom) | ESLint rules for use with [jest-dom](https://testing-library.com/docs/ecosystem-jest-dom). | Dynamic enabled | diff --git a/index.js b/index.js index 0f165cc..55e1f9f 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires const readPkgUp = require("read-pkg-up"); +let hasPrettier = false; let hasJestDom = false; let hasTestingLibrary = false; let hasEmotion = false; @@ -13,6 +14,7 @@ try { ...packageJson.dependencies, }); + hasPrettier = allDeps.includes("prettier"); hasJestDom = allDeps.includes("@testing-library/jest-dom"); hasTestingLibrary = allDeps.includes("@testing-library/react") || @@ -38,9 +40,9 @@ module.exports = { "plugin:jest/style", hasJestDom && "plugin:jest-dom/recommended", hasTestingLibrary && "plugin:testing-library/react", - "plugin:prettier/recommended", - "prettier/@typescript-eslint", - "prettier/react", + hasPrettier && "prettier", + hasPrettier && "prettier/@typescript-eslint", + hasPrettier && "prettier/react", ].filter(Boolean), plugins: [ "@typescript-eslint", @@ -48,7 +50,6 @@ module.exports = { hasJestDom && "jest-dom", hasTestingLibrary && "testing-library", hasEmotion && "emotion", - "prettier", ].filter(Boolean), settings: { "import/resolver": { @@ -83,6 +84,5 @@ module.exports = { "emotion/styled-import": "error", } : null), - "prettier/prettier": "error", }, }; diff --git a/linter.js b/linter.js index ceacfdf..a0519b3 100644 --- a/linter.js +++ b/linter.js @@ -1,3 +1,5 @@ +/* eslint-disable */ + const config = require("./index"); config.rules["jest/no-deprecated-functions"] = "off"; module.exports = config; diff --git a/package.json b/package.json index 851395d..34b81f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-config-welly", - "version": "1.4.12", + "version": "1.5.0", "description": "ESLint configuration for React projects that I do. Feel free to use this!", "license": "MIT", "homepage": "https://github.com/wellyshen/eslint-config-welly", @@ -26,7 +26,9 @@ ], "scripts": { "test": "eslint tests/*", - "lint": "eslint --fix index.js", + "lint": "yarn lint:code && yarn lint:format", + "lint:code": "eslint --fix index.js", + "lint:format": "prettier -w . -u --loglevel silent", "preversion": "yarn lint", "postversion": "git push --follow-tags --no-verify && npm publish" }, @@ -37,7 +39,7 @@ }, "lint-staged": { "index.js": "eslint --fix", - "**/*": "prettier --write --ignore-unknown" + "**/*": "prettier -w -u" }, "eslintConfig": { "extends": "./linter.js" @@ -54,7 +56,6 @@ "eslint-plugin-jest": "^24.1.0", "eslint-plugin-jest-dom": "^3.2.3", "eslint-plugin-jsx-a11y": "^6.3.0", - "eslint-plugin-prettier": "^3.1.4", "eslint-plugin-react": "^7.20.0", "eslint-plugin-react-hooks": "^4", "eslint-plugin-testing-library": "^3.9.1", @@ -67,7 +68,6 @@ }, "peerDependencies": { "eslint": "^7.2.0", - "prettier": "^2.1.2", "typescript": "^4.0.3" }, "engines": {