Skip to content
/ jest Public
forked from jestjs/jest

Commit

Permalink
Use eslint plugins to run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Jul 6, 2017
1 parent a7acc5a commit 35dd339
Show file tree
Hide file tree
Showing 33 changed files with 523 additions and 285 deletions.
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',
],
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
26 changes: 19 additions & 7 deletions website/core/BlogPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class BlogPost extends React.Component {
content = content.split('<!--truncate-->')[0];
return (
<article className="post-content">
<Marked>{content}</Marked>
<Marked>
{content}
</Marked>
<div className="read-more">
<a className="button" href={'/jest/blog/' + this.props.post.path}>
Read More
Expand All @@ -27,7 +29,11 @@ class BlogPost extends React.Component {
</article>
);
}
return <Marked>{content}</Marked>;
return (
<Marked>
{content}
</Marked>
);
}

renderAuthorPhoto() {
Expand All @@ -39,8 +45,8 @@ class BlogPost extends React.Component {
<img
src={
'https://graph.facebook.com/' +
post.authorFBID +
'/picture/?height=200&width=200'
post.authorFBID +
'/picture/?height=200&width=200'
}
/>
</a>
Expand All @@ -55,7 +61,9 @@ class BlogPost extends React.Component {
const post = this.props.post;
return (
<h1>
<a href={'/jest/blog/' + post.path}>{post.title}</a>
<a href={'/jest/blog/' + post.path}>
{post.title}
</a>
</h1>
);
}
Expand Down Expand Up @@ -83,13 +91,17 @@ class BlogPost extends React.Component {

const githubButton = this.props.truncate
? null
: <p className="post-meta">{siteConfig.githubButton}</p>;
: <p className="post-meta">
{siteConfig.githubButton}
</p>;

return (
<header className="postHeader">
{this.renderAuthorPhoto()}
<p className="post-authorName">
<a href={post.authorURL} target="_blank">{post.author}</a>
<a href={post.authorURL} target="_blank">
{post.author}
</a>
</p>
{this.renderTitle()}
{githubButton}
Expand Down
12 changes: 7 additions & 5 deletions website/core/BlogSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @jsx React.DOM
*/

/* eslint-disable sort-keys */
/* eslint-disable sort-keys */

const MetadataBlog = require('MetadataBlog');
const React = require('React');
Expand All @@ -14,10 +14,12 @@ const SideNav = require('SideNav');

const BlogSidebar = React.createClass({
render() {
const contents = [{
name: 'Recent Posts',
links: MetadataBlog.files,
}];
const contents = [
{
name: 'Recent Posts',
links: MetadataBlog.files,
},
];
const title = this.props.current && this.props.current.title;
const current = {
id: title || '',
Expand Down
6 changes: 1 addition & 5 deletions website/core/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ class Button extends React.Component {
render() {
return (
<div className="pluginWrapper buttonWrapper">
<a
className="button"
href={this.props.href}
target={this.props.target}
>
<a className="button" href={this.props.href} target={this.props.target}>
{this.props.children}
</a>
</div>
Expand Down
Loading

0 comments on commit 35dd339

Please sign in to comment.