Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use eslint plugins to run prettier #3971

Merged
merged 3 commits into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module.exports = {
extends: [
'./packages/eslint-config-fb-strict/index.js',
'plugin:import/errors',
'prettier',
'prettier/flowtype',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem like any flowtype style rules were applied, so might want to remove this

],
overrides: [
// to make it more suitable for running on code examples in docs/ folder
Expand Down Expand Up @@ -56,11 +58,31 @@ module.exports = {
'unicorn/filename-case': 0,
},
},
{
excludedFiles: 'integration_tests/__tests__/**/*',
files: [
'examples/**/*',
'scripts/**/*',
'integration_tests/*/**/*',
'website/server/*',
'website/layout/*',
],
rules: {
'prettier/prettier': [
2,
{
bracketSpacing: false,
printWidth: 80,
singleQuote: true,
trailingComma: 'es5',
},
],
},
},
],
parser: 'babel-eslint',
plugins: ['markdown', 'import', 'unicorn'],
plugins: ['markdown', 'import', 'unicorn', 'prettier'],
rules: {
'computed-property-spacing': 0,
'flowtype/boolean-style': 2,
'flowtype/no-primitive-constructor-types': 2,
'flowtype/require-valid-file-annotation': 2,
Expand All @@ -72,8 +94,15 @@ module.exports = {
// This has to be disabled until all type and module imports are combined
// https://github.com/benmosher/eslint-plugin-import/issues/645
'import/order': 0,
'max-len': 0,
'no-multiple-empty-lines': 1,
'prettier/prettier': [
2,
{
bracketSpacing: false,
printWidth: 80,
singleQuote: true,
trailingComma: 'all',
},
],
'unicorn/filename-case': [2, {case: 'snakeCase'}],
},
};
2 changes: 0 additions & 2 deletions fixtures/parser_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function parserTests(parse: (file: string) => BabylonParserResult) {
});

describe('File Parsing for it blocks', () => {

it('For the simplest it cases', () => {
const data = parse(`${fixtures}/global_its.example`);

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

describe('File Parsing for expects', () => {

it('finds Expects in a danger test file', () => {
const data = parse(`${fixtures}/dangerjs/travis-ci.example`);
expect(data.expects.length).toEqual(8);
Expand Down
4 changes: 1 addition & 3 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
module.exports = config => {
config.set({
browsers: ['ChromeHeadless'],
files: [
'integration_tests/browser-support/browser-test.js',
],
files: ['integration_tests/browser-support/browser-test.js'],
frameworks: ['mocha', 'browserify'],
plugins: ['karma-browserify', 'karma-chrome-launcher', 'karma-mocha'],
preprocessors: {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
"cross-spawn": "^5.1.0",
"enzyme": "^2.8.2",
"eslint": "^4.1.0",
"eslint-config-prettier": "^2.3.0",
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-flowtype": "^2.34.0",
"eslint-plugin-import": "^2.6.0",
"eslint-plugin-markdown": "^1.0.0-beta.6",
"eslint-plugin-prettier": "^2.1.2",
"eslint-plugin-react": "^7.1.0",
"eslint-plugin-unicorn": "^2.1.2",
"flow-bin": "^0.48.0",
Expand Down Expand Up @@ -74,10 +76,8 @@
"clean-all": "rm -rf ./node_modules && rm -rf ./packages/*/node_modules && rm -rf ./integration_tests/*/*/node_modules && yarn run build-clean",
"jest": "node ./packages/jest-cli/bin/jest.js",
"jest-coverage": "yarn run jest --silent -- --coverage",
"lint": "yarn run lint-prettier --silent && eslint . --cache --ext js,md",
"lint": "eslint . --cache --ext js,md",
"lint-es5-build": "eslint --no-eslintrc --no-ignore --env=browser packages/*/build-es5",
"lint-prettier": "node scripts/prettier.js lint",
"prettier": "node scripts/prettier.js write",
"postinstall": "node ./scripts/postinstall.js && yarn run build --silent && (cd packages/eslint-plugin-jest && yarn link --silent) && yarn link eslint-plugin-jest --silent",
"publish": "yarn run build-clean --silent && yarn run build --silent && lerna publish --silent",
"test-ci-es5-build-in-browser": "karma start --single-run",
Expand Down
53 changes: 36 additions & 17 deletions packages/eslint-config-fb-strict/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
const fbjsConfig = require('eslint-config-fbjs');

const variableNamePattern = String.raw`\s*[a-zA-Z_$][a-zA-Z_$\d]*\s*`;
const importPattern = String.raw`^(?:var|let|const|import type)\s+` +
'{?' + variableNamePattern + '(?:,' + variableNamePattern + ')*}?' +
const importPattern =
String.raw`^(?:var|let|const|import type)\s+` +
'{?' +
variableNamePattern +
'(?:,' +
variableNamePattern +
')*}?' +
String.raw`\s*(?:=\s*require\(|from)[a-zA-Z_+./''\s\d\-]+\)?[^;\n]*[;\n]`;
const maxLenIgnorePattern = String.raw`(^\s*(it|test)\(|${importPattern})`;

Expand All @@ -29,24 +34,31 @@ module.exports = Object.assign({}, fbjsConfig, {
'array-bracket-spacing': [2, 'never'],
'arrow-parens': [2, 'as-needed'],
'arrow-spacing': [2],
'brace-style': [2, '1tbs', {
'allowSingleLine': true,
}],
'brace-style': [
2,
'1tbs',
{
allowSingleLine: true,
},
],
'comma-dangle': [2, 'always-multiline'],
'comma-spacing': [2],
'comma-style': [2, 'last'],
'computed-property-spacing': [2, 'never'],
'eol-last': [2],
'flowtype/object-type-delimiter': [2, 'comma'],
'indent': [0],
indent: [0],
'jest/no-focused-tests': [2],
'jest/no-identical-title': [2],
'jest/valid-expect': [2],
'max-len': [2, {
'code': 80,
'ignorePattern': maxLenIgnorePattern,
'ignoreUrls': true,
}],
'max-len': [
2,
{
code: 80,
ignorePattern: maxLenIgnorePattern,
ignoreUrls: true,
},
],
'no-const-assign': [2],
'no-extra-parens': [2, 'functions'],
'no-irregular-whitespace': [2],
Expand All @@ -56,14 +68,21 @@ module.exports = Object.assign({}, fbjsConfig, {
'object-shorthand': [2],
'prefer-arrow-callback': [2],
'prefer-const': [2],
'quotes': [2, 'single', {
'allowTemplateLiterals': true,
'avoidEscape': true,
}],
'semi': [2, 'always'],
quotes: [
2,
'single',
{
allowTemplateLiterals: true,
avoidEscape: true,
},
],
semi: [2, 'always'],
'sort-keys': [2],
'space-before-blocks': [2],
'space-before-function-paren': [2, {anonymous: 'never', asyncArrow: 'always', named: 'never'}],
'space-before-function-paren': [
2,
{anonymous: 'never', asyncArrow: 'always', named: 'never'},
],
'space-in-parens': [2, 'never'],
}),
});
32 changes: 17 additions & 15 deletions packages/pretty-format/perf/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ function testCase(name, fn) {
}

function test(name, value, ignoreResult, prettyFormatOpts) {
const formatted = testCase(
'prettyFormat() ',
() => prettyFormat(value, prettyFormatOpts)
const formatted = testCase('prettyFormat() ', () =>
prettyFormat(value, prettyFormatOpts),
);

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

results.forEach((item, index) => {
item.isWinner = index === 0;
item.isLoser = index === results.length - 1;
item.isLoser = index === results.length - 1;
});

function log(current) {
Expand All @@ -86,8 +85,11 @@ function test(name, value, ignoreResult, prettyFormatOpts) {
}
if (current.total) {
message +=
' - ' + (current.total / NANOSECONDS) + 's total (' +
TIMES_TO_RUN + ' runs)';
' - ' +
current.total / NANOSECONDS +
's total (' +
TIMES_TO_RUN +
' runs)';
}
if (current.error) {
message += ' - Error: ' + current.error.message;
Expand All @@ -103,11 +105,11 @@ function test(name, value, ignoreResult, prettyFormatOpts) {
message = chalk.dim(message);
}

const diff = (current.time - winner.time);
const diff = current.time - winner.time;

if (diff > (winner.time * 0.85)) {
if (diff > winner.time * 0.85) {
message = chalk.bgRed.black(message);
} else if (diff > (winner.time * 0.65)) {
} else if (diff > winner.time * 0.65) {
message = chalk.bgYellow.black(message);
} else if (!current.error) {
message = chalk.bgGreen.black(message);
Expand Down Expand Up @@ -166,7 +168,7 @@ objectWithPropsAndSymbols[Symbol('symbol2')] = 'value3';
test('an object with properties and symbols', objectWithPropsAndSymbols);
test('an object with sorted properties', {a: 2, b: 1});
test('regular expressions from constructors', new RegExp('regexp'));
test('regular expressions from literals', /regexp/ig);
test('regular expressions from literals', /regexp/gi);
test('an empty set', new Set());
const setWithValues = new Set();
setWithValues.add('value1');
Expand Down Expand Up @@ -199,11 +201,11 @@ const element = React.createElement(
{onClick: () => {}, prop: {a: 1, b: 2}},
React.createElement('div', {prop: {a: 1, b: 2}}),
React.createElement('div'),
React.createElement('div', {prop: {a: 1, b: 2}},
React.createElement('div', null,
React.createElement('div')
)
)
React.createElement(
'div',
{prop: {a: 1, b: 2}},
React.createElement('div', null, React.createElement('div')),
),
);

test('react', ReactTestRenderer.create(element).toJSON(), false, {
Expand Down
85 changes: 0 additions & 85 deletions scripts/prettier.js

This file was deleted.

Loading