Skip to content

Commit 1700a40

Browse files
SimenBcpojer
authored andcommitted
Use eslint plugins to run prettier (jestjs#3971)
* Use eslint plugins to run prettier Fixes jestjs#3575 * Remove redundant prettier script file * Don't run prettier on markdown files (they are not fixable)
1 parent a7acc5a commit 1700a40

34 files changed

+524
-370
lines changed

.eslintrc.js

+34-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module.exports = {
1010
extends: [
1111
'./packages/eslint-config-fb-strict/index.js',
1212
'plugin:import/errors',
13+
'prettier',
14+
'prettier/flowtype',
1315
],
1416
overrides: [
1517
// to make it more suitable for running on code examples in docs/ folder
@@ -23,6 +25,7 @@ module.exports = {
2325
'jest/valid-expect': 0,
2426
'no-undef': 0,
2527
'no-unused-vars': 0,
28+
'prettier/prettier': 0,
2629
'react/jsx-no-undef': 0,
2730
'react/react-in-jsx-scope': 0,
2831
'sort-keys': 0,
@@ -56,11 +59,31 @@ module.exports = {
5659
'unicorn/filename-case': 0,
5760
},
5861
},
62+
{
63+
excludedFiles: 'integration_tests/__tests__/**/*',
64+
files: [
65+
'examples/**/*',
66+
'scripts/**/*',
67+
'integration_tests/*/**/*',
68+
'website/server/*',
69+
'website/layout/*',
70+
],
71+
rules: {
72+
'prettier/prettier': [
73+
2,
74+
{
75+
bracketSpacing: false,
76+
printWidth: 80,
77+
singleQuote: true,
78+
trailingComma: 'es5',
79+
},
80+
],
81+
},
82+
},
5983
],
6084
parser: 'babel-eslint',
61-
plugins: ['markdown', 'import', 'unicorn'],
85+
plugins: ['markdown', 'import', 'unicorn', 'prettier'],
6286
rules: {
63-
'computed-property-spacing': 0,
6487
'flowtype/boolean-style': 2,
6588
'flowtype/no-primitive-constructor-types': 2,
6689
'flowtype/require-valid-file-annotation': 2,
@@ -72,8 +95,15 @@ module.exports = {
7295
// This has to be disabled until all type and module imports are combined
7396
// https://github.com/benmosher/eslint-plugin-import/issues/645
7497
'import/order': 0,
75-
'max-len': 0,
76-
'no-multiple-empty-lines': 1,
98+
'prettier/prettier': [
99+
2,
100+
{
101+
bracketSpacing: false,
102+
printWidth: 80,
103+
singleQuote: true,
104+
trailingComma: 'all',
105+
},
106+
],
77107
'unicorn/filename-case': [2, {case: 'snakeCase'}],
78108
},
79109
};

fixtures/parser_tests.js

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ function parserTests(parse: (file: string) => BabylonParserResult) {
1818
});
1919

2020
describe('File Parsing for it blocks', () => {
21-
2221
it('For the simplest it cases', () => {
2322
const data = parse(`${fixtures}/global_its.example`);
2423

@@ -122,7 +121,6 @@ function parserTests(parse: (file: string) => BabylonParserResult) {
122121
});
123122

124123
describe('File Parsing for expects', () => {
125-
126124
it('finds Expects in a danger test file', () => {
127125
const data = parse(`${fixtures}/dangerjs/travis-ci.example`);
128126
expect(data.expects.length).toEqual(8);

karma.conf.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
module.exports = config => {
1010
config.set({
1111
browsers: ['ChromeHeadless'],
12-
files: [
13-
'integration_tests/browser-support/browser-test.js',
14-
],
12+
files: ['integration_tests/browser-support/browser-test.js'],
1513
frameworks: ['mocha', 'browserify'],
1614
plugins: ['karma-browserify', 'karma-chrome-launcher', 'karma-mocha'],
1715
preprocessors: {

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
"cross-spawn": "^5.1.0",
2424
"enzyme": "^2.8.2",
2525
"eslint": "^4.1.0",
26+
"eslint-config-prettier": "^2.3.0",
2627
"eslint-plugin-babel": "^4.1.1",
2728
"eslint-plugin-flowtype": "^2.34.0",
2829
"eslint-plugin-import": "^2.6.0",
2930
"eslint-plugin-markdown": "^1.0.0-beta.6",
31+
"eslint-plugin-prettier": "^2.1.2",
3032
"eslint-plugin-react": "^7.1.0",
3133
"eslint-plugin-unicorn": "^2.1.2",
3234
"flow-bin": "^0.48.0",
@@ -74,10 +76,8 @@
7476
"clean-all": "rm -rf ./node_modules && rm -rf ./packages/*/node_modules && rm -rf ./integration_tests/*/*/node_modules && yarn run build-clean",
7577
"jest": "node ./packages/jest-cli/bin/jest.js",
7678
"jest-coverage": "yarn run jest --silent -- --coverage",
77-
"lint": "yarn run lint-prettier --silent && eslint . --cache --ext js,md",
79+
"lint": "eslint . --cache --ext js,md",
7880
"lint-es5-build": "eslint --no-eslintrc --no-ignore --env=browser packages/*/build-es5",
79-
"lint-prettier": "node scripts/prettier.js lint",
80-
"prettier": "node scripts/prettier.js write",
8181
"postinstall": "node ./scripts/postinstall.js && yarn run build --silent && (cd packages/eslint-plugin-jest && yarn link --silent) && yarn link eslint-plugin-jest --silent",
8282
"publish": "yarn run build-clean --silent && yarn run build --silent && lerna publish --silent",
8383
"test-ci-es5-build-in-browser": "karma start --single-run",

packages/eslint-config-fb-strict/index.js

+36-17
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@
1111
const fbjsConfig = require('eslint-config-fbjs');
1212

1313
const variableNamePattern = String.raw`\s*[a-zA-Z_$][a-zA-Z_$\d]*\s*`;
14-
const importPattern = String.raw`^(?:var|let|const|import type)\s+` +
15-
'{?' + variableNamePattern + '(?:,' + variableNamePattern + ')*}?' +
14+
const importPattern =
15+
String.raw`^(?:var|let|const|import type)\s+` +
16+
'{?' +
17+
variableNamePattern +
18+
'(?:,' +
19+
variableNamePattern +
20+
')*}?' +
1621
String.raw`\s*(?:=\s*require\(|from)[a-zA-Z_+./''\s\d\-]+\)?[^;\n]*[;\n]`;
1722
const maxLenIgnorePattern = String.raw`(^\s*(it|test)\(|${importPattern})`;
1823

@@ -29,24 +34,31 @@ module.exports = Object.assign({}, fbjsConfig, {
2934
'array-bracket-spacing': [2, 'never'],
3035
'arrow-parens': [2, 'as-needed'],
3136
'arrow-spacing': [2],
32-
'brace-style': [2, '1tbs', {
33-
'allowSingleLine': true,
34-
}],
37+
'brace-style': [
38+
2,
39+
'1tbs',
40+
{
41+
allowSingleLine: true,
42+
},
43+
],
3544
'comma-dangle': [2, 'always-multiline'],
3645
'comma-spacing': [2],
3746
'comma-style': [2, 'last'],
3847
'computed-property-spacing': [2, 'never'],
3948
'eol-last': [2],
4049
'flowtype/object-type-delimiter': [2, 'comma'],
41-
'indent': [0],
50+
indent: [0],
4251
'jest/no-focused-tests': [2],
4352
'jest/no-identical-title': [2],
4453
'jest/valid-expect': [2],
45-
'max-len': [2, {
46-
'code': 80,
47-
'ignorePattern': maxLenIgnorePattern,
48-
'ignoreUrls': true,
49-
}],
54+
'max-len': [
55+
2,
56+
{
57+
code: 80,
58+
ignorePattern: maxLenIgnorePattern,
59+
ignoreUrls: true,
60+
},
61+
],
5062
'no-const-assign': [2],
5163
'no-extra-parens': [2, 'functions'],
5264
'no-irregular-whitespace': [2],
@@ -56,14 +68,21 @@ module.exports = Object.assign({}, fbjsConfig, {
5668
'object-shorthand': [2],
5769
'prefer-arrow-callback': [2],
5870
'prefer-const': [2],
59-
'quotes': [2, 'single', {
60-
'allowTemplateLiterals': true,
61-
'avoidEscape': true,
62-
}],
63-
'semi': [2, 'always'],
71+
quotes: [
72+
2,
73+
'single',
74+
{
75+
allowTemplateLiterals: true,
76+
avoidEscape: true,
77+
},
78+
],
79+
semi: [2, 'always'],
6480
'sort-keys': [2],
6581
'space-before-blocks': [2],
66-
'space-before-function-paren': [2, {anonymous: 'never', asyncArrow: 'always', named: 'never'}],
82+
'space-before-function-paren': [
83+
2,
84+
{anonymous: 'never', asyncArrow: 'always', named: 'never'},
85+
],
6786
'space-in-parens': [2, 'never'],
6887
}),
6988
});

packages/pretty-format/perf/test.js

+17-15
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ function testCase(name, fn) {
5151
}
5252

5353
function test(name, value, ignoreResult, prettyFormatOpts) {
54-
const formatted = testCase(
55-
'prettyFormat() ',
56-
() => prettyFormat(value, prettyFormatOpts)
54+
const formatted = testCase('prettyFormat() ', () =>
55+
prettyFormat(value, prettyFormatOpts),
5756
);
5857

5958
const inspected = testCase('util.inspect() ', () => {
@@ -75,7 +74,7 @@ function test(name, value, ignoreResult, prettyFormatOpts) {
7574

7675
results.forEach((item, index) => {
7776
item.isWinner = index === 0;
78-
item.isLoser = index === results.length - 1;
77+
item.isLoser = index === results.length - 1;
7978
});
8079

8180
function log(current) {
@@ -86,8 +85,11 @@ function test(name, value, ignoreResult, prettyFormatOpts) {
8685
}
8786
if (current.total) {
8887
message +=
89-
' - ' + (current.total / NANOSECONDS) + 's total (' +
90-
TIMES_TO_RUN + ' runs)';
88+
' - ' +
89+
current.total / NANOSECONDS +
90+
's total (' +
91+
TIMES_TO_RUN +
92+
' runs)';
9193
}
9294
if (current.error) {
9395
message += ' - Error: ' + current.error.message;
@@ -103,11 +105,11 @@ function test(name, value, ignoreResult, prettyFormatOpts) {
103105
message = chalk.dim(message);
104106
}
105107

106-
const diff = (current.time - winner.time);
108+
const diff = current.time - winner.time;
107109

108-
if (diff > (winner.time * 0.85)) {
110+
if (diff > winner.time * 0.85) {
109111
message = chalk.bgRed.black(message);
110-
} else if (diff > (winner.time * 0.65)) {
112+
} else if (diff > winner.time * 0.65) {
111113
message = chalk.bgYellow.black(message);
112114
} else if (!current.error) {
113115
message = chalk.bgGreen.black(message);
@@ -166,7 +168,7 @@ objectWithPropsAndSymbols[Symbol('symbol2')] = 'value3';
166168
test('an object with properties and symbols', objectWithPropsAndSymbols);
167169
test('an object with sorted properties', {a: 2, b: 1});
168170
test('regular expressions from constructors', new RegExp('regexp'));
169-
test('regular expressions from literals', /regexp/ig);
171+
test('regular expressions from literals', /regexp/gi);
170172
test('an empty set', new Set());
171173
const setWithValues = new Set();
172174
setWithValues.add('value1');
@@ -199,11 +201,11 @@ const element = React.createElement(
199201
{onClick: () => {}, prop: {a: 1, b: 2}},
200202
React.createElement('div', {prop: {a: 1, b: 2}}),
201203
React.createElement('div'),
202-
React.createElement('div', {prop: {a: 1, b: 2}},
203-
React.createElement('div', null,
204-
React.createElement('div')
205-
)
206-
)
204+
React.createElement(
205+
'div',
206+
{prop: {a: 1, b: 2}},
207+
React.createElement('div', null, React.createElement('div')),
208+
),
207209
);
208210

209211
test('react', ReactTestRenderer.create(element).toJSON(), false, {

scripts/prettier.js

-85
This file was deleted.

0 commit comments

Comments
 (0)