From b7fbf89ed606b250e0d138734fcb3caa66147498 Mon Sep 17 00:00:00 2001 From: Christophe Hurpeau Date: Wed, 20 Jan 2021 11:10:12 +0100 Subject: [PATCH] feat: use prettier outside eslint https://github.com/christophehurpeau/pob/commit/445e2cc4def17c3eef1da69c9112dcc1d9e005ce#diff-df15dc66e5815ea34cf86fb16ce789512f2d366a59aa63ce0cf87a96d12cb813 https://github.com/christophehurpeau/eslint-config-pob/commit/f2d3b30ba6bb9d2ba8cb0d9c80eafb6fb868680b https://github.com/prettier/eslint-plugin-prettier/issues/304 https://prettier.io/docs/en/integrating-with-linters.html#notes --- .circleci/config.yml | 6 +-- .prettierignore | 1 + @ornikar/browserslist-config/README.md | 6 +-- @ornikar/eslint-config/package.json | 1 - @ornikar/eslint-config/plugins/prettier.js | 3 -- @ornikar/postcss-config/README.md | 12 ++--- .../createLintStagedConfig.js | 2 +- .../repo-config/createLintStagedConfig.js | 15 ++---- @ornikar/rollup-config/README.md | 4 +- @ornikar/test.json | 1 + README.md | 50 +++++++++---------- package.json | 3 +- yarn.lock | 19 ------- 13 files changed, 44 insertions(+), 79 deletions(-) create mode 100644 .prettierignore create mode 100644 @ornikar/test.json diff --git a/.circleci/config.yml b/.circleci/config.yml index ba443f496..9d44ff414 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -73,12 +73,12 @@ jobs: executor: frontend/node steps: - checkout-and-restore-cache + - frontend/lint: + step-name: Prettier + script: prettier - frontend/lint: step-name: ESLint script: eslint - - frontend/lint: - step-name: Prettier JSON - script: prettier-json # ------------------------------------------------------------------------------------------------- # WORKFLOWS diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..1b763b1ba --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +CHANGELOG.md diff --git a/@ornikar/browserslist-config/README.md b/@ornikar/browserslist-config/README.md index 159a23ff7..135b7afcb 100644 --- a/@ornikar/browserslist-config/README.md +++ b/@ornikar/browserslist-config/README.md @@ -8,15 +8,13 @@ in `package.json`: ```json { - "browserslist": [ - "extends @ornikar/browserlist-config" - ] + "browserslist": ["extends @ornikar/browserlist-config"] } ``` ## Supported browsers - Degraded support: https://browserl.ist/?q=last+4+versions%2C+%3E+.2%25+in+FR%2C+Firefox+ESR%2C+not+ie+%3C+10%2C+not+ios+%3C+10%2C+not+op_mini+all -- Full support: https://browserl.ist/?q=last+4+versions%2C+%3E+1%25+in+FR%2C+Firefox+ESR%2C+not+ie+%3C+12%2C+not+op_mini+all +- Full support: https://browserl.ist/?q=last+4+versions%2C+%3E+1%25+in+FR%2C+Firefox+ESR%2C+not+ie+%3C+12%2C+not+op_mini+all Degraded support: the website must be usable but don't have to be pixel perfect or pretty. diff --git a/@ornikar/eslint-config/package.json b/@ornikar/eslint-config/package.json index a26021f4e..14fc429c0 100644 --- a/@ornikar/eslint-config/package.json +++ b/@ornikar/eslint-config/package.json @@ -17,7 +17,6 @@ "eslint-plugin-filenames": "^1.3.2", "eslint-plugin-import": "^2.20.2", "eslint-plugin-jsx-a11y": "^6.2.3", - "eslint-plugin-prettier": "^3.1.1", "eslint-plugin-unicorn": "^14.0.1" }, "peerDependencies": { diff --git a/@ornikar/eslint-config/plugins/prettier.js b/@ornikar/eslint-config/plugins/prettier.js index deac9986e..ef707d0f3 100644 --- a/@ornikar/eslint-config/plugins/prettier.js +++ b/@ornikar/eslint-config/plugins/prettier.js @@ -1,12 +1,9 @@ 'use strict'; module.exports = { - plugins: ['prettier'], extends: ['eslint-config-prettier'].map(require.resolve), rules: { - 'prettier/prettier': 'error', - // https://github.com/prettier/eslint-config-prettier#curly // prettier doesn't enforce {} with multiline curly: ['error', 'multi-line'], diff --git a/@ornikar/postcss-config/README.md b/@ornikar/postcss-config/README.md index d88961750..d20101b92 100644 --- a/@ornikar/postcss-config/README.md +++ b/@ornikar/postcss-config/README.md @@ -8,13 +8,13 @@ Configure browserslist with `@ornikar/browserslist-config`. Create `postcss.config.js`: -```js +```js const plugins = require('@ornikar/postcss-config'); module.exports = ({ options }) => ({ plugins: [ ...plugins.syntaxPlugins(), - + plugins.themePlugin({ importFrom: 'path/to/theme.css', preserve: process.env.NODE_ENV !== 'production', @@ -26,13 +26,11 @@ module.exports = ({ options }) => ({ }), plugins.autoprefixerPlugin(), - + // add other plugins if you need to :) - + // production - ...(process.env.NODE_ENV === 'production' - ? plugins.productionPlugins() - : []), + ...(process.env.NODE_ENV === 'production' ? plugins.productionPlugins() : []), ], }); ``` diff --git a/@ornikar/repo-config-react/createLintStagedConfig.js b/@ornikar/repo-config-react/createLintStagedConfig.js index 59d039488..88aa04e48 100644 --- a/@ornikar/repo-config-react/createLintStagedConfig.js +++ b/@ornikar/repo-config-react/createLintStagedConfig.js @@ -7,7 +7,7 @@ const createBaseLintStagedConfig = require('@ornikar/repo-config/createLintStage const pkg = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf-8')); module.exports = function createLintStagedConfig(options = {}) { - const config = createBaseLintStagedConfig({ srcExtensions: ['js', 'ts', 'tsx'] }); + const config = createBaseLintStagedConfig({ srcExtensions: ['js', 'mjs', 'ts', 'tsx'] }); // eslint-disable-next-line prefer-destructuring const srcDirectories = createBaseLintStagedConfig.getSrcDirectories(); diff --git a/@ornikar/repo-config/createLintStagedConfig.js b/@ornikar/repo-config/createLintStagedConfig.js index ce9a11dac..a1396e286 100644 --- a/@ornikar/repo-config/createLintStagedConfig.js +++ b/@ornikar/repo-config/createLintStagedConfig.js @@ -13,7 +13,7 @@ const getSrcDirectories = (srcDirectoryName = 'src') => workspaces ? `{${workspaces.join(',')}}${srcDirectoryName && `/${srcDirectoryName}`}` : srcDirectoryName; module.exports = function createLintStagedConfig(options = {}) { - const srcExtensions = options.srcExtensions || ['js']; + const srcExtensions = options.srcExtensions || ['js', 'mjs', 'ts']; const srcDirectories = getSrcDirectories(options.srcDirectoryName); return { @@ -33,17 +33,10 @@ module.exports = function createLintStagedConfig(options = {}) { shouldGenerateTsconfigInLernaRepo && 'git add **/tsconfig.json **/tsconfig.build.json', ].filter(Boolean); }, - [`{*.json${workspaces ? `,${workspaces.map((workspacePath) => `${workspacePath}/*.json`).join(',')}` : ''}}`]: ( - filenames, - ) => { - const filteredFilenames = filenames.filter((name) => !name.endsWith('/package.json')); - if (filteredFilenames.length === 0) return []; - return [`prettier --write ${filteredFilenames.join(' ')}`]; - }, + '!(package).json': ['prettier --write'], + '*.{yml,yaml,md,html}': ['prettier --write'], + [`*.{${srcExtensions.join(',')}}`]: ['prettier --write', 'eslint --fix --quiet'], [`{.storybook,${srcDirectories}}/**/*.css`]: ['prettier --parser css --write', 'stylelint --quiet --fix'], - - [`${srcDirectories}/**/*.{${srcExtensions.join(',')}}`]: ['eslint --fix --quiet'], - '{scripts,config,.storyboook}/*.js': ['eslint --fix --quiet'], }; }; diff --git a/@ornikar/rollup-config/README.md b/@ornikar/rollup-config/README.md index 72bce2571..190da685b 100644 --- a/@ornikar/rollup-config/README.md +++ b/@ornikar/rollup-config/README.md @@ -2,14 +2,12 @@ Ornikar rollup config - create a file `rollup.config.js`: -```js +```js 'use strict'; const createConfig = require('@ornikar/rollup-config'); module.exports = createConfig(); - ``` diff --git a/@ornikar/test.json b/@ornikar/test.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/@ornikar/test.json @@ -0,0 +1 @@ +{} diff --git a/README.md b/README.md index d8c2e0c8e..2d343dc63 100644 --- a/README.md +++ b/README.md @@ -10,28 +10,28 @@ This repository is a monorepo that we manage using [Lerna](https://github.com/lerna/lerna). -| Package | Version | Description | -|---------|---------|-------------| -| [@ornikar/browserslist-config](/@ornikar/browserslist-config) | | browserslist config -| [@ornikar/commitlint-config](/@ornikar/commitlint-config) | | commitlint config -| [@ornikar/eslint-config](/@ornikar/eslint-config) | | eslint config files -| [@ornikar/eslint-config-babel](/@ornikar/eslint-config-babel) | | eslint babel config files -| [@ornikar/eslint-config-babel-use](/@ornikar/eslint-config-babel-use) | | eslint babel use config files -| [@ornikar/eslint-config-formatjs](/@ornikar/eslint-config-formatjs) | | eslint formatjs config files -| [@ornikar/eslint-config-node](/@ornikar/eslint-config-node) | | eslint node config files -| [@ornikar/eslint-config-react](/@ornikar/eslint-config-react) | | eslint react config files -| [@ornikar/eslint-config-typescript](/@ornikar/eslint-config-typescript) | | eslint typescript config files -| [@ornikar/eslint-config-typescript-react](/@ornikar/eslint-config-typescript-react) | | eslint typescript-react config files -| [@ornikar/intl-config](/@ornikar/intl-config) | | intl config -| [@ornikar/jest-config](/@ornikar/jest-config) | | jest config -| [@ornikar/jest-config-react](/@ornikar/jest-config-react) | | jest react config -| [@ornikar/lerna-config](/@ornikar/lerna-config) | | lerna config -| [@ornikar/postcss-config](/@ornikar/postcss-config) | | postcss config -| [@ornikar/prettier-config](/@ornikar/prettier-config) | | prettier config -| [@ornikar/renovate-config](/@ornikar/renovate-config) | | renovate config -| [@ornikar/repo-config](/@ornikar/repo-config) | | repo config -| [@ornikar/repo-config-react](/@ornikar/repo-config-react) | | react repo config -| [@ornikar/rollup-config](/@ornikar/rollup-config) | | rollup config -| [@ornikar/storybook-config](/@ornikar/storybook-config) | | storybook config -| [@ornikar/stylelint-config](/@ornikar/stylelint-config) | | stylelint config -| [@ornikar/webpack-config](/@ornikar/webpack-config) | | webpack config +| Package | Version | Description | +| ----------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ | +| [@ornikar/browserslist-config](/@ornikar/browserslist-config) | | browserslist config | +| [@ornikar/commitlint-config](/@ornikar/commitlint-config) | | commitlint config | +| [@ornikar/eslint-config](/@ornikar/eslint-config) | | eslint config files | +| [@ornikar/eslint-config-babel](/@ornikar/eslint-config-babel) | | eslint babel config files | +| [@ornikar/eslint-config-babel-use](/@ornikar/eslint-config-babel-use) | | eslint babel use config files | +| [@ornikar/eslint-config-formatjs](/@ornikar/eslint-config-formatjs) | | eslint formatjs config files | +| [@ornikar/eslint-config-node](/@ornikar/eslint-config-node) | | eslint node config files | +| [@ornikar/eslint-config-react](/@ornikar/eslint-config-react) | | eslint react config files | +| [@ornikar/eslint-config-typescript](/@ornikar/eslint-config-typescript) | | eslint typescript config files | +| [@ornikar/eslint-config-typescript-react](/@ornikar/eslint-config-typescript-react) | | eslint typescript-react config files | +| [@ornikar/intl-config](/@ornikar/intl-config) | | intl config | +| [@ornikar/jest-config](/@ornikar/jest-config) | | jest config | +| [@ornikar/jest-config-react](/@ornikar/jest-config-react) | | jest react config | +| [@ornikar/lerna-config](/@ornikar/lerna-config) | | lerna config | +| [@ornikar/postcss-config](/@ornikar/postcss-config) | | postcss config | +| [@ornikar/prettier-config](/@ornikar/prettier-config) | | prettier config | +| [@ornikar/renovate-config](/@ornikar/renovate-config) | | renovate config | +| [@ornikar/repo-config](/@ornikar/repo-config) | | repo config | +| [@ornikar/repo-config-react](/@ornikar/repo-config-react) | | react repo config | +| [@ornikar/rollup-config](/@ornikar/rollup-config) | | rollup config | +| [@ornikar/storybook-config](/@ornikar/storybook-config) | | storybook config | +| [@ornikar/stylelint-config](/@ornikar/stylelint-config) | | stylelint config | +| [@ornikar/webpack-config](/@ornikar/webpack-config) | | webpack config | diff --git a/package.json b/package.json index 8bf75505b..7f7006fbf 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,8 @@ "private": true, "repository": "ornikar/shared-configs", "scripts": { + "lint:prettier": "prettier --check .", "lint:eslint": "eslint --ext .js --fix .", - "lint:prettier-json": "prettier --check {*.json,@ornikar/*/*.json}", "release": "lerna publish --conventional-commits -m 'chore: release'" }, "prettier": "./@ornikar/prettier-config", @@ -32,7 +32,6 @@ "eslint-plugin-filenames": "1.3.2", "eslint-plugin-import": "2.22.1", "eslint-plugin-node": "10.0.0", - "eslint-plugin-prettier": "3.3.1", "eslint-plugin-unicorn": "14.0.1", "husky": "4.3.8", "lerna": "3.22.1", diff --git a/yarn.lock b/yarn.lock index 38f4e6192..445947a82 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3879,13 +3879,6 @@ eslint-plugin-prefer-class-properties@^1.0.0: dependencies: requireindex "~1.1.0" -eslint-plugin-prettier@3.3.1, eslint-plugin-prettier@^3.1.1: - version "3.3.1" - resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.3.1.tgz#7079cfa2497078905011e6f82e8dd8453d1371b7" - integrity sha512-Rq3jkcFY8RYeQLgk2cCwuc0P7SEFwDravPhsJZOQ5N4YI4DSg50NyqJ/9gdZHzQlHf8MvafSesbNJCcP/FF6pQ== - dependencies: - prettier-linter-helpers "^1.0.0" - eslint-plugin-react-hooks@^2.5.0: version "2.5.1" resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-2.5.1.tgz#4ef5930592588ce171abeb26f400c7fbcbc23cd0" @@ -4195,11 +4188,6 @@ fast-deep-equal@^2.0.1: resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49" integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk= -fast-diff@^1.1.2: - version "1.2.0" - resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03" - integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w== - fast-glob@^2.2.6: version "2.2.6" resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-2.2.6.tgz#a5d5b697ec8deda468d85a74035290a025a95295" @@ -7671,13 +7659,6 @@ prelude-ls@~1.1.2: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ= -prettier-linter-helpers@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b" - integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w== - dependencies: - fast-diff "^1.1.2" - prettier@2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5"