Skip to content

Commit 47b3226

Browse files
committed
Create initial eslint extension
Add useful plugins and examples - eslint-plugin-deprecate - eslint-plugin-html - eslint-plugin-jsdoc - eslint-plugin-json - eslint-plugin-sonarjs Enable warnings/errors on rules Tree cares about. Disable `object-curly-spacing`, because Dewey hates it. Turn off sonarjs recommended warnings, by default. Add commonly-used global definitions and environments. Update README.
1 parent 8bc5afe commit 47b3226

File tree

11 files changed

+325
-1
lines changed

11 files changed

+325
-1
lines changed

.eslintrc.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// 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.
2+
module.exports = {
3+
extends: [
4+
'frontier',
5+
'./index.js',
6+
'plugin:eslint-plugin-sonarjs/recommended'
7+
],
8+
rules: {
9+
'deprecate/function': ['error',
10+
{'name': 'deprecatedFunction', 'use': 'function x from package y'}
11+
],
12+
'deprecate/import': ['error',
13+
{'name': 'path/to/legacyModule', 'use': 'module x'}
14+
],
15+
'deprecate/member-expression': ['error',
16+
{'name': '$.each', 'use': 'native forEach'}
17+
]
18+
}
19+
}

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
**/.DS_Store
2+
*.esproj
3+
*.iml
4+
*.ipr
5+
*.iws
6+
*.orig
7+
.idea
8+
.monitor
9+
.vscode/*
10+
**/node_modules
11+
/reports/**
12+
analysis.json
13+
npm-debug.log

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
11
# eslint-config-tree
2-
Tree custom lint configuration
2+
3+
This is a shared configuration for all Tree repositories. Contains overrides and enhancements on top of the base configuration located at [https://github.com/fs-webdev/eslint-config-frontier](https://github.com/fs-webdev/eslint-config-frontier).
4+
5+
Utilizes the following plugins:
6+
7+
- [eslint-plugin-deprecate](https://github.com/AlexMost/eslint-plugin-deprecate)
8+
- [eslint-plugin-html](https://github.com/BenoitZugmeyer/eslint-plugin-html)
9+
- [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import)
10+
- [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc)
11+
- [eslint-plugin-json](https://github.com/azeemba/eslint-plugin-json)
12+
- [eslint-plugin-node](https://github.com/mysticatea/eslint-plugin-node)
13+
- [eslint-plugin-promise](https://github.com/xjamundx/eslint-plugin-promise)
14+
- [eslint-plugin-sonarjs](https://github.com/SonarSource/eslint-plugin-sonarjs)
15+
- [eslint-config-standard](https://github.com/standard/eslint-config-standard)

demo/example-eslint-results.png

3.57 MB
Loading

demo/example.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* Example of a broken JSON file that should trigger the additional rules contained in ./index.js */
2+
3+
// fixMe: Actually make this work
4+
// todo: Add documentation
5+
// Hack: Note that these work, regardless of case
6+
// Here be Dragons
7+
8+
/* Tree considers the following as errors:
9+
no-unused-vars
10+
*/
11+
12+
/* Tree considers the following as warnings:
13+
no-undefined
14+
*/
15+
16+
/**
17+
* @function _fetchPreferences - Fetch a user's tree-view-options preference so that we know what options to call the tree-data endpoint with.
18+
* @param a
19+
* @returns
20+
*/
21+
function ONE_FUNCTION_TO_BRING_THEM_ALL_AND_IN_THE_DARKNESS_BIND_THEM (params) {
22+
}
23+
24+
let variable = (true) ? true : true;
25+
26+
if (window === undefined && window === undefined) {
27+
ONE_FUNCTION_TO_BRING_THEM_ALL_AND_IN_THE_DARKNESS_BIND_THEM('a', 'b');
28+
const deprecatedImport = require('path/to/legacyModule');
29+
deprecatedImport.execute();
30+
deprecatedFunction();
31+
$.each();
32+
debugger;// Make sure we get in here to set the value correctly
33+
}

demo/example.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* Example of a broken JSON file that should trigger the additional rules contained in ./index.js */
2+
{
3+
"": {
4+
'key' : Array,
5+
"key" "value"
6+
"key": "value",
7+
}
8+
};

demo/test/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
6+
7+
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
8+
<script src="../../web-component-tester/browser.js"></script>
9+
</head>
10+
<body>
11+
<script>
12+
// Load and run all tests (.html, .js):
13+
WCT.loadSuites([
14+
'unit_test.html'
15+
]);
16+
</script>
17+
18+
</body></html>

demo/test/unit_test.html

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!--
2+
NOTE: We don't actually have any WCT needed dependencies included in this repository for the tests to actually be able to run. This file is included for eslint environment config demonstration purposes, only.
3+
-->
4+
<!doctype html>
5+
<html>
6+
<head>
7+
<meta charset="utf-8">
8+
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
9+
10+
<title>example unit_test</title>
11+
12+
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
13+
<script src="../../web-component-tester/browser.js"></script>
14+
15+
<script src="../example.js"></script>
16+
17+
</head>
18+
<body>
19+
20+
<test-fixture id="example-fixture">
21+
<template>
22+
<example></example>
23+
</template>
24+
</test-fixture>
25+
26+
<script>
27+
document.addEventListener('WebComponentsReady', () => {
28+
let exampleComponent;
29+
let windowParent;
30+
31+
before(() => {
32+
windowParent = window.parent;
33+
});
34+
35+
beforeEach(() => {
36+
exampleComponent = fixture('example-fixture');
37+
document.body.append(exampleComponent);
38+
});
39+
40+
afterEach(() => {
41+
document.body.removeChild(exampleComponent);
42+
});
43+
44+
after(() => {
45+
windowParent = null;
46+
});
47+
48+
describe('functions', () => {
49+
describe('ONE_FUNCTION_TO_BRING_THEM_ALL_AND_IN_THE_DARKNESS_BIND_THEM', () => {
50+
let consoleSpy;
51+
52+
beforeEach(() => {
53+
consoleSpy = sinon.spy(console, 'warn');
54+
});
55+
56+
afterEach(() => {
57+
consoleSpy.restore();
58+
});
59+
60+
it('should work', () => {
61+
if (windowParent) {
62+
assert.true(true, true);
63+
expect(consoleSpy.calledOnce, 'result was not logged to the console').to.equal(true);
64+
}
65+
});
66+
});
67+
});
68+
});
69+
</script>
70+
71+
</body>
72+
</html>

index.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
module.exports = {
2+
extends: [
3+
'eslint-config-standard'
4+
// '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.
5+
],
6+
env: {
7+
'browser': true,
8+
'mocha': true
9+
},
10+
/**
11+
* @property globals - Tree set of typical global variables, to avoid numerous `no-undef` errors.
12+
*/
13+
globals: {
14+
'__services__': true,
15+
'assert': true,
16+
'axe': true,
17+
'customElements': true,
18+
'CustomEvent': true,
19+
'Event': true,
20+
'expect': true,
21+
'fixture': true,
22+
'FS': true,
23+
'FsBehaviors': true,
24+
'Headers': true,
25+
'HTMLElement': true,
26+
'indexedDB': true,
27+
'location': true,
28+
'Polymer': true,
29+
'ResettablePropertiesBehavior': true,
30+
'sessionStorage': true,
31+
'sinon': true,
32+
'WCI18n': true,
33+
'WCT': true
34+
},
35+
parser: 'babel-eslint',
36+
/**
37+
* @property plugins - Tree additional linter plugins.
38+
*/
39+
plugins: [
40+
'eslint-plugin-deprecate',
41+
'eslint-plugin-html',
42+
'eslint-plugin-jsdoc',
43+
'eslint-plugin-json',
44+
'eslint-plugin-sonarjs'
45+
],
46+
/**
47+
* @property rules - Tree custom rule and additional linter configuration.
48+
*/
49+
rules: {
50+
'jsdoc/check-alignment': 'warn',
51+
'jsdoc/check-examples': 'warn',
52+
'jsdoc/check-indentation': 'off',
53+
'jsdoc/check-param-names': 'warn',
54+
'jsdoc/check-syntax': 'warn',
55+
'jsdoc/check-tag-names': 'warn',
56+
'jsdoc/check-types': 'warn',
57+
'jsdoc/implements-on-classes': 'warn',
58+
'jsdoc/match-description': 'warn',
59+
'jsdoc/newline-after-description': 'off',
60+
'jsdoc/no-types': 'off',
61+
'jsdoc/no-undefined-types': 'warn',
62+
'jsdoc/require-description-complete-sentence': 'warn',
63+
'jsdoc/require-description': 'warn',
64+
'jsdoc/require-example': 'off',
65+
'jsdoc/require-hyphen-before-param-description': 'warn',
66+
'jsdoc/require-jsdoc': 'warn',
67+
'jsdoc/require-param-description': 'warn',
68+
'jsdoc/require-param-name': 'warn',
69+
'jsdoc/require-param-type': 'warn',
70+
'jsdoc/require-param': 'warn',
71+
'jsdoc/require-returns-check': 'warn',
72+
'jsdoc/require-returns-description': 'warn',
73+
'jsdoc/require-returns-type': 'warn',
74+
'jsdoc/require-returns': 'warn',
75+
'jsdoc/valid-types': 'warn',
76+
77+
'no-extra-semi': 'error',
78+
'no-warning-comments': ['warn', { 'terms': ['FIXME', 'TODO', 'TO-DO', 'HACK', 'HERE BE DRAGONS'], 'location': 'anywhere' }],
79+
'no-undefined': 'warn',
80+
'object-curly-spacing': 'off',
81+
'semi': ['error', 'always'],
82+
83+
'sonarjs/cognitive-complexity': 'warn',
84+
'sonarjs/max-switch-cases': 'warn',
85+
'sonarjs/no-all-duplicated-branches': 'warn',
86+
'sonarjs/no-duplicate-string': 'warn',
87+
'sonarjs/no-duplicated-branches': 'warn',
88+
'sonarjs/no-element-overwrite': 'warn',
89+
'sonarjs/no-extra-arguments': 'warn',
90+
'sonarjs/no-identical-conditions': 'warn',
91+
'sonarjs/no-identical-functions': 'warn',
92+
'sonarjs/no-identical-expressions': 'warn',
93+
'sonarjs/no-inverted-boolean-check': 'warn',
94+
'sonarjs/no-one-iteration-loop': 'warn',
95+
'sonarjs/no-redundant-boolean': 'warn',
96+
'sonarjs/no-small-switch': 'warn',
97+
'sonarjs/no-use-of-empty-return-value': 'warn',
98+
'sonarjs/no-useless-catch': 'warn',
99+
'sonarjs/prefer-immediate-return': 'warn',
100+
'sonarjs/prefer-object-literal': 'warn',
101+
'sonarjs/prefer-single-boolean-return': 'warn',
102+
'sonarjs/prefer-while': 'warn'
103+
104+
// See eslint-config-tree/.eslintrc.js for example deprecation rules.
105+
}
106+
};

0 commit comments

Comments
 (0)