diff --git a/.eslintrc.yml b/.eslintrc.yml index 8f3eae9e2..e584ce975 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1,6 +1,5 @@ extends: - sinon - - plugin:prettier/recommended globals: ArrayBuffer: false @@ -12,12 +11,16 @@ globals: plugins: - ie11 - "@sinonjs/no-prototype-methods" - - prettier rules: - prettier/prettier: error ie11/no-collection-args: error ie11/no-for-in-const: error ie11/no-loop-func: warn ie11/no-weak-collections: error "@sinonjs/no-prototype-methods/no-prototype-methods": error + # the sinon config is currently using prettier plugin + # once that has been updated, this line can be removed + # See https://github.com/sinonjs/eslint-config-sinon/blob/956db70f2e0566d0e7f8f1f093da4704cf16afb2/index.js#L288-L290 + prettier/prettier: off + # This needs to go into eslint-config-sinon + quotes: off diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..f36c7a9d0 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,11 @@ +coverage/ +pkg/ +tmp/ +.sass-cache +docs/_site/ +docs/js/ +docs/releases/ +docs/_releases/ +docs/assets/js/ +CHANGELOG.md +docs/changelog.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 17ae7a2db..859bcb4f5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -76,7 +76,7 @@ Sinon.JS uses [ESLint](http://eslint.org) to keep the codebase free of lint, and If you are contributing to a Sinon project, you'll probably want to configure your editors ([ESLint](https://eslint.org/docs/user-guide/integrations#editors), [Prettier](https://prettier.io/docs/en/editors.html)) to make editing code a more enjoyable experience. -The ESLint verification (which includes Prettier) will be run before unit tests in the CI environment. The build will fail if the source code does not pass the style check. +Both Prettier and ESLint will check the code in pre-commit hooks (when installed) and will be run before unit tests in the CI environment. The build will fail if the source code does not pass the checks. You can run the linter locally: @@ -84,12 +84,24 @@ You can run the linter locally: $ npm run lint ``` -You can fix a lot of lint and style violations automatically: +You can fix a lot of lint violations automatically: ``` $ npm run lint -- --fix ``` +You can run prettier locally: + +``` +$ npm run prettier:check +``` + +You can fix style violations automatically: + +``` +$ npm run prettier:write +``` + To ensure consistent reporting of lint warnings, you should use the same versions of ESLint and Prettier as defined in `package.json` (which is what the CI servers use). ### Run the tests diff --git a/package.json b/package.json index 7585cae81..55820e8d9 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,8 @@ "postbuild": "npm run test-esm-bundle", "prepublishOnly": "npm run build", "prettier": "prettier lib/**/*.js test/**/*.js", + "prettier:check": "prettier --check '**/*.{js,css,md}'", + "prettier:write": "prettier --write '**/*.{js,css,md}'", "preversion": "./scripts/preversion.sh", "postversion": "./scripts/postversion.sh" }, @@ -64,9 +66,9 @@ ] }, "lint-staged": { + "*.{js,css,md}": "prettier --check", "*.js": "eslint", - "*.mjs": "eslint --ext mjs --parser-options=sourceType:module", - "docs/**/*.md": "markdownlint" + "*.mjs": "eslint --ext mjs --parser-options=sourceType:module" }, "dependencies": { "@sinonjs/commons": "^1.8.1",