This repository has been archived by the owner on Sep 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update linter with support for prettier, easier installation, new con…
…figs This new linter config integrates Prettier with ESLint and relies on ESLint's `--fix` option instead of running Prettier separately. ESLint delegates to Prettier, so `// prettier-ignore` and the `.prettierignore` file still work in addition to ESLint's inline-comment options. There are four linter configs: default, native, web, node. You usually want to use one of the latter three. All three include support for React and Prettier. This also bumps the line length to 100. Going to publish this as 6.0.0-rc.0 and using it in a few projects. Test Plan: Added Jest tests that (a) verify the configs are properly formatted, (b) can run on files as expected, and (c) don't have rules that overlap with Prettier's. (c) is a subjective choice -- it means that if you tell Prettier to ignore some code, ESLint won't enforce some stylistic rules that Prettier normally would take care of -- sometimes that's what you want and sometimes it isn't so I picked the option that gets out of your hair. Also some ESLint rules that support `--fix` ended up duplicating Prettier's work and would add two semicolons or two commas in some places. fbshipit-source-id: cdda43f
- Loading branch information
Showing
27 changed files
with
1,051 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = { | ||
extends: './react.js', | ||
extends: './node.js', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`fixtures/all-00.js 1`] = ` | ||
Object { | ||
"errorCount": 0, | ||
"filePath": "/Users/ide/universe/libraries/eslint-config-expo/__tests__/fixtures/all-00.js", | ||
"fixableErrorCount": 0, | ||
"fixableWarningCount": 0, | ||
"messages": Array [], | ||
"output": "import 'hi'; | ||
import a from 'a'; | ||
import { b } from 'b'; | ||
import c, { c1 } from 'c'; | ||
import * as d from 'd'; | ||
import e from './e'; | ||
@d | ||
export class Example { | ||
static s = { | ||
a, | ||
b, | ||
}; | ||
m = {}; | ||
hi() { | ||
_fn(); | ||
} | ||
async byeAsync() { | ||
_fn(a, b, c, c1, d, e); | ||
} | ||
} | ||
function _fn() {} | ||
", | ||
"warningCount": 0, | ||
} | ||
`; | ||
|
||
exports[`message 1`] = ` | ||
"No rules that are unnecessary or conflict with Prettier were found. | ||
" | ||
`; | ||
|
||
exports[`success 1`] = `true`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`fixtures/all-00.js 1`] = ` | ||
Object { | ||
"errorCount": 0, | ||
"filePath": "/Users/ide/universe/libraries/eslint-config-expo/__tests__/fixtures/all-00.js", | ||
"fixableErrorCount": 0, | ||
"fixableWarningCount": 0, | ||
"messages": Array [], | ||
"output": "import 'hi'; | ||
import a from 'a'; | ||
import { b } from 'b'; | ||
import c, { c1 } from 'c'; | ||
import * as d from 'd'; | ||
import e from './e'; | ||
@d | ||
export class Example { | ||
static s = { | ||
a, | ||
b, | ||
}; | ||
m = {}; | ||
hi() { | ||
_fn(); | ||
} | ||
async byeAsync() { | ||
_fn(a, b, c, c1, d, e); | ||
} | ||
} | ||
function _fn() {} | ||
", | ||
"warningCount": 0, | ||
} | ||
`; | ||
|
||
exports[`fixtures/web-native-00.js 1`] = ` | ||
Object { | ||
"errorCount": 0, | ||
"filePath": "/Users/ide/universe/libraries/eslint-config-expo/__tests__/fixtures/web-native-00.js", | ||
"fixableErrorCount": 0, | ||
"fixableWarningCount": 0, | ||
"messages": Array [], | ||
"warningCount": 0, | ||
} | ||
`; | ||
|
||
exports[`fixtures/web-native-01.js 1`] = ` | ||
Object { | ||
"errorCount": 0, | ||
"filePath": "/Users/ide/universe/libraries/eslint-config-expo/__tests__/fixtures/web-native-01.js", | ||
"fixableErrorCount": 0, | ||
"fixableWarningCount": 0, | ||
"messages": Array [ | ||
Object { | ||
"column": 3, | ||
"endColumn": 22, | ||
"endLine": 4, | ||
"line": 4, | ||
"message": "props should be placed after render", | ||
"nodeType": "ClassProperty", | ||
"ruleId": "react/sort-comp", | ||
"severity": 1, | ||
"source": " props = { x: 'x' };", | ||
}, | ||
Object { | ||
"column": 5, | ||
"endColumn": 19, | ||
"endLine": 7, | ||
"line": 7, | ||
"message": "Unexpected alert.", | ||
"nodeType": "CallExpression", | ||
"ruleId": "no-alert", | ||
"severity": 1, | ||
"source": " alert('uh oh');", | ||
}, | ||
Object { | ||
"column": 5, | ||
"endColumn": 18, | ||
"endLine": 8, | ||
"line": 8, | ||
"message": "Do not use setState in componentDidMount", | ||
"nodeType": "MemberExpression", | ||
"ruleId": "react/no-did-mount-set-state", | ||
"severity": 1, | ||
"source": " this.setState({});", | ||
}, | ||
], | ||
"output": "import React from 'react'; | ||
export default class Example extends React.Component { | ||
props = { x: 'x' }; | ||
componentDidMount() { | ||
alert('uh oh'); | ||
this.setState({}); | ||
} | ||
render() { | ||
return ( | ||
<div> | ||
{this.props.x} | ||
</div> | ||
); | ||
} | ||
} | ||
", | ||
"warningCount": 3, | ||
} | ||
`; | ||
|
||
exports[`fixtures/web-native-02.js 1`] = ` | ||
Object { | ||
"errorCount": 0, | ||
"filePath": "/Users/ide/universe/libraries/eslint-config-expo/__tests__/fixtures/web-native-02.js", | ||
"fixableErrorCount": 0, | ||
"fixableWarningCount": 0, | ||
"messages": Array [ | ||
Object { | ||
"column": 3, | ||
"endColumn": 25, | ||
"endLine": 10, | ||
"line": 10, | ||
"message": "componentDidMount should be placed before componentDidUpdate", | ||
"nodeType": "MethodDefinition", | ||
"ruleId": "react/sort-comp", | ||
"severity": 1, | ||
"source": " componentDidMount() {}", | ||
}, | ||
], | ||
"source": "import React from 'react'; | ||
export default class Example extends React.Component { | ||
componentDidUpdate() {} | ||
render() { | ||
return null; | ||
} | ||
componentDidMount() {} | ||
static getInitialProps() {} | ||
} | ||
", | ||
"warningCount": 1, | ||
} | ||
`; | ||
|
||
exports[`message 1`] = ` | ||
"No rules that are unnecessary or conflict with Prettier were found. | ||
" | ||
`; | ||
|
||
exports[`success 1`] = `true`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`fixtures/all-00.js 1`] = ` | ||
Object { | ||
"errorCount": 0, | ||
"filePath": "/Users/ide/universe/libraries/eslint-config-expo/__tests__/fixtures/all-00.js", | ||
"fixableErrorCount": 0, | ||
"fixableWarningCount": 0, | ||
"messages": Array [], | ||
"output": "import 'hi'; | ||
import a from 'a'; | ||
import { b } from 'b'; | ||
import c, { c1 } from 'c'; | ||
import * as d from 'd'; | ||
import e from './e'; | ||
@d | ||
export class Example { | ||
static s = { | ||
a, | ||
b, | ||
}; | ||
m = {}; | ||
hi() { | ||
_fn(); | ||
} | ||
async byeAsync() { | ||
_fn(a, b, c, c1, d, e); | ||
} | ||
} | ||
function _fn() {} | ||
", | ||
"warningCount": 0, | ||
} | ||
`; | ||
|
||
exports[`message 1`] = ` | ||
"No rules that are unnecessary or conflict with Prettier were found. | ||
" | ||
`; | ||
|
||
exports[`success 1`] = `true`; |
Oops, something went wrong.