Skip to content

Commit 6122432

Browse files
authored
Add helpful ESLint plugins (#2)
- eslint-plugin-no-only-tests - eslint-plugin-no-skip-tests - eslint-plugin-test-selectors // NOTE: Only runs against JSX Add note to check promising plugins in the future. Add test files to demonstrate new rules and update snapshot. Release version 2.0.0.
1 parent 2d83a9f commit 6122432

9 files changed

+85
-31
lines changed

.eslintrc.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
// Basic .eslintrc.js file that loads the the frontier shared eslint configuration, and then the extension/override provided by the configuration in index.js just for local demonstration purposes. Also contains example `deprecate` rules.
22
module.exports = {
33
extends: [
4-
'frontier',
5-
'./index.js',
6-
'plugin:eslint-plugin-sonarjs/recommended'
4+
'eslint-config-frontier',
5+
'plugin:eslint-plugin-sonarjs/recommended',
6+
'plugin:promise/recommended',
7+
'./index.js'
78
],
89
plugins: [
910
// Enable plugins that are not natively supported by Code Climate. Otherwise results in build errors.
1011
'eslint-plugin-bestpractices',
1112
'eslint-plugin-deprecate',
12-
'eslint-plugin-sonarjs'
13+
'eslint-plugin-no-only-tests',
14+
'eslint-plugin-no-skip-tests',
15+
'eslint-plugin-sonarjs',
16+
'eslint-plugin-test-selectors' // NOTE: Only runs against JSX
1317
],
1418
rules: {
1519
'deprecate/function': ['error',

README.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,36 @@ Utilizes the following plugins:
77
- [eslint-plugin-bestpractices](https://github.com/skye2k2/eslint-plugin-bestpractices)
88
- [eslint-plugin-deprecate](https://github.com/AlexMost/eslint-plugin-deprecate)
99
- [eslint-plugin-html](https://github.com/BenoitZugmeyer/eslint-plugin-html)
10-
- [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import)
1110
- [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc)
1211
- [eslint-plugin-json](https://github.com/azeemba/eslint-plugin-json)
13-
- [eslint-plugin-node](https://github.com/mysticatea/eslint-plugin-node)
12+
- [eslint-plugin-no-only-tests](https://github.com/levibuzolic/eslint-plugin-no-only-tests)
13+
- [eslint-plugin-no-skip-tests](https://github.com/romaingaillardjs/eslint-plugin-no-skip-tests)
1414
- [eslint-plugin-promise](https://github.com/xjamundx/eslint-plugin-promise)
1515
- [eslint-plugin-sonarjs](https://github.com/SonarSource/eslint-plugin-sonarjs)
1616
- [eslint-config-standard](https://github.com/standard/eslint-config-standard)
1717

18+
> POTENTIALLY WORTH CONSIDERING IN THE FUTURE (MAY NOT WORK BECAUSE OF NEEDING SOMETHING LIKE BABEL?):
19+
20+
> - 'eslint-plugin-i18next' // SEEMS LIKE TOO MANY FALSE POSITIVES
21+
> - 'eslint-plugin-json-format' // DOESN'T SEEM TO WORK
22+
> - 'eslint-plugin-package-json' // undefined TypeErrors while parsing package.json
23+
> - 'eslint-plugin-sort-keys-fix' // RUINS INDENTATION, DOES NOT BRING JSDOCS ALONG
1824
1925
![alt text](demo/example-eslint-results.png "Example linting infractions for things the Tree team cares about")
2026

2127
## Usage:
2228

23-
1. Add either `eslint-config-tree` or `eslint-config-frontier-react` as a devDependency.
29+
1. Add either `eslint-config-frontier` or `eslint-config-frontier-react` as a devDependency.
2430

2531
1. Add this repository as a package devDependency:
2632

27-
> "eslint-config-tree": "github:fs-webdev/eslint-config-tree#semver:^1",
33+
> "eslint-config-tree": "github:fs-webdev/eslint-config-tree#semver:^2",
2834
2935
1. In your `eslintrc.js` file, put the following:
3036
<pre><code>module.exports = {
3137
extends: [
32-
'frontier',
33-
'tree'
38+
'eslint-config-frontier', // or '@fs/eslint-config-frontier-react'
39+
'eslint-config-tree'
3440
],
3541
plugins: [
3642
'eslint-plugin-bestpractices',

demo/example.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function ONE_FUNCTION_TO_BRING_THEM_ALL_AND_IN_THE_DARKNESS_BIND_THEM (params) {
2929

3030
let variable = (true) ? true : true;
3131

32-
if (window === undefined && window === undefined) {
32+
if (window === undefined && window === undefined && true === params) {
3333
ONE_FUNCTION_TO_BRING_THEM_ALL_AND_IN_THE_DARKNESS_BIND_THEM('a', 'b');
3434
const deprecatedImport = require('path/to/legacyModule');
3535
deprecatedImport.execute();

demo/example.test.html

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script>
2+
var chai = require('chai');
3+
var assert = chai.assert;
4+
5+
describe.only('example.test.js', () => {
6+
it.only('should pass', () => {
7+
assert.true(true);
8+
});
9+
10+
it.skip('should pass', () => {
11+
assert.true(true);
12+
});
13+
});
14+
</script>

demo/test/lint-output.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ test('Should have consistent rule output', async t => {
66
return fileManager.readFile('./demo/test/snapshots/new-lint-results.txt')
77
.then((content) => {
88
const eslintOutput = content.toString(); // content is instance of Buffer, so it needs to be parsed
9-
t.snapshot(eslintOutput);
9+
return t.snapshot(eslintOutput);
1010
})
1111
.catch((err) => {
1212
console.log(err);
13-
t.fail();
13+
return t.fail();
1414
});
1515
});

demo/test/snapshots/lint-output.js.md

+15-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Generated by [AVA](https://ava.li).
99
> Snapshot 1
1010
1111
`␊
12+
example.test.html␊
13+
5:12 error describe.only not permitted no-only-tests/no-only-tests␊
14+
6:8 error it.only not permitted no-only-tests/no-only-tests␊
15+
10:8 warning it.skip not permitted no-skip-tests/no-skip-tests␊
16+
1217
example.js␊
1318
6:0 warning Inline eslint-disable found bestpractices/no-eslint-disable␊
1419
8:1 warning Unexpected 'FIXME' comment no-warning-comments␊
@@ -18,25 +23,27 @@ Generated by [AVA](https://ava.li).
1823
21:1 warning Missing JSDoc @description declaration jsdoc/require-description␊
1924
21:1 warning JSDoc @returns declaration present but return expression not available in function jsdoc/require-returns-check␊
2025
21:1 warning JSDoc syntax error valid-jsdoc␊
21-
23:0 warning Expected @param names to be "params". Got "a, b" jsdoc/check-param-names␊
2226
23:0 warning Missing JSDoc @param "a" description jsdoc/require-param-description␊
23-
24:0 warning Missing JSDoc @param "b" type jsdoc/require-param-type
27+
23:0 warning Expected @param names to be "params". Got "a, b" jsdoc/check-param-names
2428
24:0 warning Missing JSDoc @param "b" description jsdoc/require-param-description␊
29+
24:0 warning Missing JSDoc @param "b" type jsdoc/require-param-type␊
2530
25:0 warning Missing JSDoc @returns type jsdoc/require-returns-type␊
2631
25:0 warning Missing JSDoc @returns description jsdoc/require-returns-description␊
2732
30:5 error 'variable' is assigned a value but never used no-unused-vars␊
28-
30:16 error This conditional operation returns the same value whether the condition is "true" or "false" sonarjs/no-all-duplicated-branches␊
33+
30:16 warning This conditional operation returns the same value whether the condition is "true" or "false" sonarjs/no-all-duplicated-branches␊
2934
30:17 error Unexpected constant condition no-constant-condition␊
3035
30:25 error Unnecessary use of boolean literals in conditional expression no-unneeded-ternary␊
31-
32:5 error Correct one of the identical sub-expressions on both sides of operator "&&" sonarjs/no-identical-expressions␊
36+
32:5 warning Correct one of the identical sub-expressions on both sides of operator "&&" sonarjs/no-identical-expressions␊
3237
32:16 warning Unexpected use of undefined no-undefined␊
3338
32:40 warning Unexpected use of undefined no-undefined␊
34-
33:3 error This function expects 1 argument, but 2 were provided sonarjs/no-extra-arguments␊
39+
32:53 error Expected literal to be on the right side of === yoda␊
40+
32:62 error 'params' is not defined no-undef␊
41+
33:3 warning This function expects 1 argument, but 2 were provided sonarjs/no-extra-arguments␊
3542
34:28 error Module path/to/legacyModule is deprecated. Use module x instead deprecate/import␊
3643
36:3 error Function deprecatedFunction is deprecated. Use function x from package y instead deprecate/function␊
3744
36:3 error 'deprecatedFunction' is not defined no-undef␊
38-
37:3 error '$' is not defined no-undef␊
3945
37:3 error Member expression $.each is deprecated. Use native forEach instead deprecate/member-expression␊
46+
37:3 error '$' is not defined no-undef␊
4047
38:3 error Unexpected 'debugger' statement no-debugger␊
4148
4249
example.json␊
@@ -48,5 +55,6 @@ Generated by [AVA](https://ava.li).
4855
6:19 error Trailing comma json/trailingcomma␊
4956
8:2 error End of file expected json/undefined␊
5057
51-
✖ 35 problems (18 errors, 17 warnings)␊
58+
✖ 40 problems (19 errors, 21 warnings)␊
59+
1 error and 0 warnings potentially fixable with the `--fix` option.␊
5260
`
157 Bytes
Binary file not shown.

index.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
extends: [
3-
'eslint-config-standard'
3+
'eslint-config-standard',
4+
'plugin:promise/recommended'
45
// 'plugin:eslint-plugin-sonarjs/recommended' // Disabled globally, for now, because it is a much higher standard than Tree's existing code currently adheres to. Enable on a case-by-case basis, if you wish.
56
],
67
env: {
@@ -48,7 +49,10 @@ module.exports = {
4849
'eslint-plugin-html',
4950
'eslint-plugin-jsdoc',
5051
'eslint-plugin-json'
51-
// 'eslint-plugin-sonarjs'
52+
// 'eslint-plugin-no-only-tests',
53+
// 'eslint-plugin-no-skip-tests',
54+
// 'eslint-plugin-sonarjs',
55+
// 'eslint-plugin-test-selectors' // NOTE: Only runs against JSX
5256
],
5357
/**
5458
* @property rules - Tree custom rule and additional linter configuration.
@@ -95,6 +99,9 @@ module.exports = {
9599

96100
'bestpractices/no-eslint-disable': 'warn',
97101

102+
'no-only-tests/no-only-tests': 'error',
103+
'no-skip-tests/no-skip-tests': 'warn',
104+
98105
'sonarjs/cognitive-complexity': 'warn',
99106
'sonarjs/max-switch-cases': 'warn',
100107
'sonarjs/no-all-duplicated-branches': 'warn',
@@ -114,7 +121,15 @@ module.exports = {
114121
'sonarjs/prefer-immediate-return': 'warn',
115122
'sonarjs/prefer-object-literal': 'warn',
116123
'sonarjs/prefer-single-boolean-return': 'warn',
117-
'sonarjs/prefer-while': 'warn'
124+
'sonarjs/prefer-while': 'warn',
125+
126+
'test-selectors/anchor': ['warn', 'always', { 'ignoreDisabled': false, 'ignoreReadonly': false }],
127+
'test-selectors/button': ['warn', 'always', { 'ignoreDisabled': false, 'ignoreReadonly': false }],
128+
'test-selectors/input': ['warn', 'always', { 'ignoreDisabled': false, 'ignoreReadonly': false }],
129+
'test-selectors/onChange': ['warn', 'always', { 'ignoreDisabled': false, 'ignoreReadonly': false }],
130+
'test-selectors/onClick': ['warn', 'always', { 'ignoreDisabled': false, 'ignoreReadonly': false }],
131+
'test-selectors/onKeyDown': ['warn', 'always', { 'ignoreDisabled': false, 'ignoreReadonly': false }],
132+
'test-selectors/onKeyUp': ['warn', 'always', { 'ignoreDisabled': false, 'ignoreReadonly': false }]
118133

119134
// See eslint-config-tree/.eslintrc.js for example deprecation rules.
120135
}

package.json

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-config-tree",
3-
"version": "1.0.15",
3+
"version": "2.0.0",
44
"description": "Shared Tree configuration that contains overrides and enhancements on top of the base frontier configuration.",
55
"main": "index.js",
66
"repository": {
@@ -23,30 +23,37 @@
2323
},
2424
"dependencies": {
2525
"babel-eslint": "^8",
26-
"eslint": "^5",
27-
"eslint-config-standard": "^12",
26+
"eslint": "^6",
2827
"eslint-config-standard-react": "^7",
28+
"eslint-config-standard": "^12",
2929
"eslint-plugin-bestpractices": "git+https://github.com/skye2k2/eslint-plugin-bestpractices.git",
3030
"eslint-plugin-deprecate": "^0.5",
3131
"eslint-plugin-html": "^6",
3232
"eslint-plugin-import": "^2",
3333
"eslint-plugin-jsdoc": "8.3.0",
3434
"eslint-plugin-json": "^1",
35+
"eslint-plugin-no-only-tests": "^2",
36+
"eslint-plugin-no-skip-tests": "^1",
3537
"eslint-plugin-node": "^9",
3638
"eslint-plugin-promise": "^4",
3739
"eslint-plugin-sonarjs": "^0.3",
38-
"eslint-plugin-standard": "^4"
40+
"eslint-plugin-standard": "^4",
41+
"eslint-plugin-test-selectors": "^1"
3942
},
4043
"devDependencies": {
4144
"ava": "^2.4.0",
4245
"eslint-config-frontier": "github:fs-webdev/eslint-config-frontier",
4346
"file-manager-js": "^3.1.6"
4447
},
48+
"resolutions": {
49+
"eslint": "^6"
50+
},
4551
"scripts": {
46-
"lint": "eslint --ignore-pattern '.*' '**/*.js' '**/*.json'",
47-
"lint:fix": "eslint --ignore-pattern '.*' '**/*.js' '**/*.json' --fix",
48-
"lint:report": "eslint --ignore-pattern '.*' '**/*.js' '**/*.json' '**/*.html' --format html --output-file ./reports/linter/lintresults.html & eslint --ignore-pattern '.*' '**/*.js' '**/*.json' --format json --output-file ./reports/linter/lintresults.json",
49-
"lint:snapshot": "eslint --ignore-pattern '.*' '**/*.js' '**/*.json' --no-color --output-file ./demo/test/snapshots/new-lint-results.txt; npm run test:format",
52+
"lint": "eslint --ignore-pattern '.*' '**/*.html' '**/*.js' '**/*.json'",
53+
"lint:fix": "eslint --ignore-pattern '.*' '**/*.html' '**/*.js' '**/*.json' --fix",
54+
"lint:quiet": "eslint --ignore-pattern '.*' '**/*.html' '**/*.js' '**/*.json' --quiet",
55+
"lint:report": "eslint --ignore-pattern '.*' '**/*.html' '**/*.js' '**/*.json' '**/*.html' --format html --output-file ./reports/linter/lintresults.html & eslint --ignore-pattern '.*' '**/*.js' '**/*.json' --format json --output-file ./reports/linter/lintresults.json",
56+
"lint:snapshot": "eslint --ignore-pattern '.*' '**/*.html' '**/*.js' '**/*.json' --no-color --output-file ./demo/test/snapshots/new-lint-results.txt; npm run test:format",
5057
"preinstall": "git config --global url.https://github.com/.insteadOf git://github.com/",
5158
"test": "npm run lint:snapshot; ava",
5259
"test:format": "sed -i '' 's|^.*eslint-config-tree/demo/||g' demo/test/snapshots/new-lint-results.txt",

0 commit comments

Comments
 (0)