Skip to content

Commit d50a4d1

Browse files
committed
feat: Replace stylistic rules with prettier
1 parent b6a0ec9 commit d50a4d1

21 files changed

+177
-97
lines changed

package-lock.json

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@
6262
"eslint-plugin-import": "^2.10.0",
6363
"eslint-plugin-jest": "^21.15.0",
6464
"eslint-plugin-jsx-a11y": "^6.0.3",
65+
"eslint-plugin-prettier": "^2.6.0",
6566
"eslint-plugin-react": "^7.7.0",
6667
"jest": "^22.4.3",
6768
"lerna": "^3.0.0-beta.14",
6869
"markdownlint-cli": "^0.8.1",
6970
"npm-run-all": "^4.1.2",
71+
"prettier": "^1.11.1",
7072
"react": "^16.3.0"
7173
},
7274
"dependencies": {

packages/eslint-config-zillow-base/.eslintrc.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
comma-dangle: off
66
# ditto for indent
77
indent: [error, 2]
8+
# far too many disagreements to be useful
9+
prettier/prettier: off

packages/eslint-config-zillow-base/README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ For example, in a JSON `.eslintrc`:
2424

2525
### `"extends": "zillow-base"`
2626

27-
Our default export contains all of our ESLint rules, including ECMAScript 6+.
27+
Our default export contains all of our ESLint rules, including ECMAScript 6+ and Prettier.
28+
29+
### `prettier` Editor Plugin Integration
30+
31+
Unfortunately, super-useful editor plugins like `prettier-atom` and `prettier-vscode` do not load Prettier settings from ESLint config, which is where we load our Prettier options from. To workaround this, add a `.prettierrc.js` or `prettier.config.js` file to your repo root with the following content:
32+
33+
```js
34+
module.exports = require('eslint-config-zillow-base/prettier.config');
35+
```
2836

2937
## Related
3038

packages/eslint-config-zillow-base/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
'./rules/variables',
88
'./rules/es6',
99
'./rules/imports',
10+
'./rules/prettier',
1011
].map(require.resolve),
1112
parserOptions: {
1213
ecmaVersion: 2017,

packages/eslint-config-zillow-base/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "index.js",
66
"files": [
77
"index.js",
8+
"prettier.config.js",
89
"rules"
910
],
1011
"scripts": {
@@ -30,7 +31,9 @@
3031
},
3132
"peerDependencies": {
3233
"eslint": "^4.18.1",
33-
"eslint-plugin-import": "^2.9.0"
34+
"eslint-plugin-import": "^2.9.0",
35+
"eslint-plugin-prettier": "^2.6.0",
36+
"prettier": "^1.11.1"
3437
},
3538
"dependencies": {
3639
"eslint-restricted-globals": "^0.1.1"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
// defaults
3+
bracketSpacing: true,
4+
jsxBracketSameLine: false,
5+
parser: 'babylon',
6+
semi: true,
7+
useTabs: false,
8+
9+
// overrides
10+
printWidth: 100,
11+
singleQuote: true,
12+
tabWidth: 4,
13+
trailingComma: 'es5',
14+
};

packages/eslint-config-zillow-base/rules/best-practices.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ module.exports = {
2323
'consistent-return': 'error',
2424

2525
// specify curly brace conventions for all control statements
26-
// FIXME: prettier override
27-
curly: ['error', 'multi-line'],
26+
// https://github.com/prettier/eslint-config-prettier#curly
27+
curly: ['error', 'all'],
2828

2929
// require default case in switch statements
3030
'default-case': ['error', { commentPattern: '^no default$' }],
@@ -34,7 +34,7 @@ module.exports = {
3434

3535
// enforces consistent newlines before or after dots
3636
// https://eslint.org/docs/rules/dot-location
37-
'dot-location': ['error', 'property'],
37+
'dot-location': ['off'/* prettier */, 'property'],
3838

3939
// require the use of === and !==
4040
// https://eslint.org/docs/rules/eqeqeq
@@ -95,7 +95,7 @@ module.exports = {
9595
'no-fallthrough': 'error',
9696

9797
// disallow the use of leading or trailing decimal points in numeric literals
98-
'no-floating-decimal': 'error',
98+
'no-floating-decimal': 'off'/* prettier */,
9999

100100
// disallow reassignments of native objects or read-only globals
101101
// https://eslint.org/docs/rules/no-global-assign
@@ -144,7 +144,7 @@ module.exports = {
144144
}],
145145

146146
// disallow use of multiple spaces
147-
'no-multi-spaces': ['error', {
147+
'no-multi-spaces': ['off'/* prettier */, {
148148
ignoreEOLComments: false,
149149
}],
150150

@@ -311,7 +311,7 @@ module.exports = {
311311

312312
// require immediate function invocation to be wrapped in parentheses
313313
// https://eslint.org/docs/rules/wrap-iife.html
314-
'wrap-iife': ['error', 'outside', { functionPrototypeMethods: false }],
314+
'wrap-iife': ['off'/* prettier */, 'outside', { functionPrototypeMethods: false }],
315315

316316
// require or disallow Yoda conditions
317317
yoda: 'error'

packages/eslint-config-zillow-base/rules/errors.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module.exports = {
6464
}],
6565

6666
// disallow unnecessary semicolons
67-
'no-extra-semi': 'error',
67+
'no-extra-semi': 'off'/* prettier */,
6868

6969
// disallow overwriting functions written as function declarations
7070
'no-func-assign': 'error',
@@ -97,7 +97,7 @@ module.exports = {
9797

9898
// Avoid code that looks like two expressions but is actually one
9999
// https://eslint.org/docs/rules/no-unexpected-multiline
100-
// FIXME: prettier override
100+
// https://github.com/prettier/eslint-config-prettier#no-unexpected-multiline
101101
'no-unexpected-multiline': 'error',
102102

103103
// disallow unreachable statements after a return, throw, continue, or break statement

packages/eslint-config-zillow-base/rules/es6.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,30 @@ module.exports = {
2121

2222
// require parens in arrow function arguments
2323
// https://eslint.org/docs/rules/arrow-parens
24-
'arrow-parens': ['error', 'as-needed', {
24+
'arrow-parens': ['off'/* prettier */, 'as-needed', {
2525
requireForBlockBody: true,
2626
}],
2727

2828
// require space before/after arrow function's arrow
2929
// https://eslint.org/docs/rules/arrow-spacing
30-
'arrow-spacing': ['error', { before: true, after: true }],
30+
'arrow-spacing': ['off'/* prettier */, { before: true, after: true }],
3131

3232
// verify super() callings in constructors
3333
'constructor-super': 'error',
3434

3535
// enforce the spacing around the * in generator functions
3636
// https://eslint.org/docs/rules/generator-star-spacing
37-
'generator-star-spacing': ['error', { before: false, after: true }],
37+
'generator-star-spacing': ['off'/* prettier */, { before: false, after: true }],
3838

3939
// disallow modifying variables of class declarations
4040
// https://eslint.org/docs/rules/no-class-assign
4141
'no-class-assign': 'error',
4242

4343
// disallow arrow functions where they could be confused with comparisons
4444
// https://eslint.org/docs/rules/no-confusing-arrow
45-
// FIXME: prettier override
45+
// https://github.com/prettier/eslint-config-prettier#no-confusing-arrow
4646
'no-confusing-arrow': ['error', {
47-
allowParens: true,
47+
allowParens: false,
4848
}],
4949

5050
// disallow modifying variables that are declared using const
@@ -153,7 +153,7 @@ module.exports = {
153153

154154
// enforce spacing between object rest-spread
155155
// https://eslint.org/docs/rules/rest-spread-spacing
156-
'rest-spread-spacing': ['error', 'never'],
156+
'rest-spread-spacing': ['off'/* prettier */, 'never'],
157157

158158
// import sorting
159159
// https://eslint.org/docs/rules/sort-imports
@@ -169,10 +169,10 @@ module.exports = {
169169

170170
// enforce usage of spacing in template strings
171171
// https://eslint.org/docs/rules/template-curly-spacing
172-
'template-curly-spacing': 'error',
172+
'template-curly-spacing': 'off'/* prettier */,
173173

174174
// enforce spacing around the * in yield* expressions
175175
// https://eslint.org/docs/rules/yield-star-spacing
176-
'yield-star-spacing': ['error', 'after']
176+
'yield-star-spacing': ['off'/* prettier */, 'after']
177177
}
178178
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const config = require('../prettier.config');
2+
3+
module.exports = {
4+
plugins: [
5+
'prettier'
6+
],
7+
8+
rules: {
9+
'prettier/prettier': ['error', config, {
10+
usePrettierrc: false
11+
}]
12+
}
13+
};

0 commit comments

Comments
 (0)