-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 896ade4
Showing
12 changed files
with
4,875 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Remove this if a parent .editorconfig is ever added to the wallet-app folder. | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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 @@ | ||
node_modules |
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 @@ | ||
v11.11.0 |
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,4 @@ | ||
# Changelog | ||
|
||
## [v0.1.0](https://github.com/uphold/eslint-config-uphold-react/releases/tag/v0.1.0) (2019-04-11) | ||
- Initial version ([NelsonBrandao](https://github.com/NelsonBrandao)) |
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,33 @@ | ||
# eslint-config-uphold-react | ||
|
||
Uphold-flavored React ESLint config. Extends [`eslint-config-uphold`](https://github.com/uphold/eslint-config-uphold). | ||
|
||
## Installation | ||
|
||
```sh | ||
$ npm install eslint eslint-config-uphold-react --save-dev | ||
``` | ||
|
||
## Usage | ||
|
||
Create an `.eslintrc.yml` file with the following: | ||
|
||
```yaml | ||
extends: uphold-react | ||
``` | ||
Add the following `script` to your `package.json`: | ||
|
||
```json | ||
{ | ||
"scripts": { | ||
"lint": "eslint ." | ||
} | ||
} | ||
``` | ||
|
||
and run the linter with: | ||
|
||
```sh | ||
$ npm run lint | ||
``` |
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,52 @@ | ||
{ | ||
"name": "eslint-config-uphold-react", | ||
"version": "0.1.0", | ||
"description": "Uphold-flavored React ESLint config", | ||
"keywords": [ | ||
"config", | ||
"eslint", | ||
"lint", | ||
"shared" | ||
], | ||
"homepage": "https://github.com/uphold/eslint-config-uphold-react#readme", | ||
"bugs": { | ||
"url": "https://github.com/uphold/eslint-config-uphold-react/issues" | ||
}, | ||
"license": "MIT", | ||
"author": "Uphold", | ||
"main": "src", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://[email protected]/uphold/eslint-config-uphold-react.git" | ||
}, | ||
"scripts": { | ||
"changelog": "github-changelog-generator --future-release=v$npm_config_future_release > CHANGELOG.md", | ||
"lint": "eslint --config src/index.js src/index.js test/rules.test.js", | ||
"unit-test": "jest", | ||
"test": "yarn run lint && yarn run unit-test", | ||
"version": "npm run changelog --future-release=$npm_package_version && git add -A CHANGELOG.md" | ||
}, | ||
"dependencies": { | ||
"babel-eslint": "^10.0.1", | ||
"eslint-config-uphold": "^0.2.0", | ||
"eslint-plugin-import": "^2.16.0", | ||
"eslint-plugin-react": "^7.12.4", | ||
"eslint-plugin-react-hooks": "^1.6.0", | ||
"eslint-plugin-sort-class-members": "^1.4.0", | ||
"jest": "^24.7.1" | ||
}, | ||
"devDependencies": { | ||
"@uphold/github-changelog-generator": "^0.8.1", | ||
"eslint": "^5.16.0", | ||
"husky": "^1.3.1", | ||
"react": "^16.8.6" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "yarn test" | ||
} | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
} | ||
} |
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,95 @@ | ||
/** | ||
* Export `uphold-react` shared configuration preset. | ||
*/ | ||
|
||
module.exports = { | ||
env: { | ||
es6: true, | ||
jasmine: true, | ||
jest: true, | ||
mocha: true, | ||
node: true | ||
}, | ||
extends: [ | ||
'plugin:react/recommended', | ||
'uphold' | ||
], | ||
parser: 'babel-eslint', | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true | ||
} | ||
}, | ||
plugins: [ | ||
'import', | ||
'react', | ||
'react-hooks', | ||
'sort-class-members' | ||
], | ||
root: true, | ||
rules: { | ||
'import/default': 'error', | ||
'import/named': 'error', | ||
'import/no-unresolved': 'error', | ||
'jsx-quotes': ['error', 'prefer-double'], | ||
'no-extra-parens': ['error', 'all', { | ||
ignoreJSX: 'all' | ||
}], | ||
'react/display-name': 'error', | ||
'react/jsx-boolean-value': 'error', | ||
'react/jsx-closing-bracket-location': 'error', | ||
'react/jsx-curly-brace-presence': ['error', { | ||
props: 'never' | ||
}], | ||
'react/jsx-curly-spacing': 'error', | ||
'react/jsx-indent': ['error', 2], | ||
'react/jsx-indent-props': ['error', 2], | ||
'react/jsx-key': 'error', | ||
'react/jsx-max-props-per-line': ['error', { maximum: 3 }], | ||
'react/jsx-no-duplicate-props': 'error', | ||
'react/jsx-no-undef': 'error', | ||
'react/jsx-sort-props': 'error', | ||
'react/jsx-tag-spacing': ['error', { | ||
afterOpening: 'never', | ||
beforeClosing: 'never', | ||
beforeSelfClosing: 'always', | ||
closingSlash: 'never' | ||
}], | ||
'react/jsx-uses-react': 'error', | ||
'react/jsx-uses-vars': 'error', | ||
'react/jsx-wrap-multilines': 'error', | ||
'react/no-danger': 'error', | ||
'react/no-direct-mutation-state': 'error', | ||
'react/no-string-refs': 'error', | ||
'react/no-unknown-property': 'error', | ||
'react/prefer-es6-class': 'error', | ||
'react/prefer-stateless-function': 'error', | ||
'react/react-in-jsx-scope': 'error', | ||
'react/self-closing-comp': 'error', | ||
'react/sort-prop-types': 'error', | ||
'react-hooks/rules-of-hooks': 'error', | ||
/* eslint-disable sort-keys */ | ||
'sort-class-members/sort-class-members': ['error', { | ||
order: [ | ||
'[static-properties-alpha]', | ||
'[static-methods-alpha]', | ||
'[properties-alpha]', | ||
'[constructor]', | ||
'[methods-alpha]' | ||
], | ||
groups: { | ||
'static-properties-alpha': [{ type: 'property', static: true, sort: 'alphabetical' }], | ||
'static-methods-alpha': [{ type: 'method', static: true, sort: 'alphabetical' }], | ||
'properties-alpha': [{ type: 'property', propertyType: 'Literal', sort: 'alphabetical' }], | ||
'methods-alpha': [{ type: 'method', sort: 'alphabetical' }] | ||
} | ||
}] | ||
/* eslint-enable sort-keys */ | ||
}, | ||
settings: { | ||
react: { | ||
pragma: 'React', | ||
version: 'detect' | ||
} | ||
} | ||
}; |
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,13 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`eslint-config-uphold-react should generate violations for incorrect code 1`] = ` | ||
Array [ | ||
"react-hooks/rules-of-hooks", | ||
"react/jsx-tag-spacing", | ||
"react/jsx-tag-spacing", | ||
"react/jsx-tag-spacing", | ||
"react/jsx-tag-spacing", | ||
"react/jsx-tag-spacing", | ||
"react/prefer-stateless-function", | ||
] | ||
`; |
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,39 @@ | ||
// `jasmine`, `jest` and `mocha` envs. | ||
|
||
// Avoid extra `no-unused-vars` violations. | ||
function noop() { | ||
// Do nothing | ||
} | ||
|
||
// `react-hooks/rules-of-hooks`. | ||
const useEffect = noop; | ||
|
||
const RulesOfHooks = () => { | ||
useEffect(noop); | ||
|
||
return null; | ||
}; | ||
|
||
noop(RulesOfHooks); | ||
|
||
// `react/jsx-tag-spacing`. | ||
const React = null; | ||
|
||
const TagSpacing = () => ( | ||
<div /> | ||
); | ||
|
||
noop(TagSpacing); | ||
|
||
// `react/prefer-stateless-function`. | ||
class PreferStatelessFunction extends React.Component { | ||
getFoo = () => { | ||
return 'foo'; | ||
} | ||
|
||
render() { | ||
return this.getFoo(); | ||
} | ||
} | ||
|
||
noop(PreferStatelessFunction); |
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,55 @@ | ||
// Avoid extra `no-unused-vars` violations. | ||
function noop() { | ||
// Do nothing | ||
} | ||
|
||
// `react-hooks/rules-of-hooks`. | ||
const useEffect = noop; | ||
|
||
const RulesOfHooks = () => { | ||
if (Math.random() > 0.5) { | ||
useEffect(noop); | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
noop(RulesOfHooks); | ||
|
||
// `react/jsx-tag-spacing`. | ||
const React = null; | ||
|
||
const TagSpacingAfterOpening = () => ( | ||
< div /> | ||
); | ||
|
||
noop(TagSpacingAfterOpening); | ||
|
||
const TagSpacingBeforeClosing = () => ( | ||
<div> | ||
{'foo'} | ||
</div > | ||
); | ||
|
||
noop(TagSpacingBeforeClosing); | ||
|
||
const TagSpacingBeforeSelfClosing = () => ( | ||
<div/> | ||
); | ||
|
||
noop(TagSpacingBeforeSelfClosing); | ||
|
||
const TagSpacingClosingSlash = () => ( | ||
<div/ > | ||
); | ||
|
||
noop(TagSpacingClosingSlash); | ||
|
||
// `react/prefer-stateless-function`. | ||
class PreferStatelessFunction extends React.Component { | ||
render() { | ||
return null; | ||
} | ||
} | ||
|
||
noop(PreferStatelessFunction); |
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,29 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
const Linter = require('eslint/lib/cli-engine'); | ||
const path = require('path'); | ||
|
||
/** | ||
* Tests for `eslint-config-uphold-react`. | ||
*/ | ||
|
||
describe('eslint-config-uphold-react', () => { | ||
const linter = new Linter({ configFile: path.join(__dirname, '..', 'src', 'index.js') }); | ||
|
||
test('should not generate any violation for correct code', () => { | ||
const source = path.join(__dirname, 'fixtures', 'correct.js'); | ||
|
||
expect(linter.executeOnFiles([source]).errorCount).toEqual(0); | ||
}); | ||
|
||
it('should generate violations for incorrect code', () => { | ||
const source = path.join(__dirname, 'fixtures', 'incorrect.js'); | ||
const rules = linter.executeOnFiles([source]).results[0].messages.map(violation => violation.ruleId); | ||
|
||
expect(rules).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.