Skip to content

Commit

Permalink
Add prettier:check and prettier:write tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
mroderick committed Jan 25, 2021
1 parent dc1d5e1 commit 36ca5fa
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
9 changes: 6 additions & 3 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
extends:
- sinon
- plugin:prettier/recommended

globals:
ArrayBuffer: false
Expand All @@ -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
11 changes: 11 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -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
16 changes: 14 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,32 @@ 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:

```
$ 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
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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",
Expand Down

0 comments on commit 36ca5fa

Please sign in to comment.