Skip to content

Commit 2c97ce9

Browse files
Improve linting to check for ES5 conformance (with exceptions to allow use of ES6 classes in certain modules) (#5342)
* Switch semistandard to standardx * Running with latest semistandard * Tighten exceptions for use of `class` as tightly as possible * Alphabetize exceptions * Enforce computed-property-spacing rule * Enforce "no-multiple-empty-lines" rule * Enforce "no-unused-expressions" rule * Enforce 'no-use-before-define' rule * Enforce 'object-curly-newline' rule * Enforce 'quotes' rule * Enforce 'spaced-comment' rule * Enforce 'valid-typeof' rule * Add comments explaining unenforced rules * Apply 'array-bracket-spacing' rule * Final comments on unused linting rules from semistandard v17 * More comments to explain config * PR review feedback * PR feedback Previous attempt didn't preserve this in forEach() callback. This version should work better (while still only using ES5 constructs). * Correct merge issue from rebase; linting issues.
1 parent 7d33792 commit 2c97ce9

27 files changed

+103
-41
lines changed

.eslintrc.json

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"extends": ["semistandard", "standard-jsx"],
3+
"parserOptions": {
4+
"ecmaVersion": 12
5+
},
6+
"rules": {
7+
/* These rules are incompatible with ES5. */
8+
"no-var": "off",
9+
"object-shorthand": "off",
10+
"prefer-const": "off",
11+
"prefer-regex-literals": "off",
12+
13+
/* These rules are compatible with ES5
14+
However they involve non-trivial code changes
15+
Therefore need more careful review before adopting. */
16+
"array-callback-return": "off",
17+
"no-mixed-operators": "off",
18+
"no-unreachable-loop": "off",
19+
"no-useless-return": "off",
20+
"prefer-promise-reject-errors": "off",
21+
22+
/* These rules are compatible with ES5
23+
However they involve large-scale changes to the codebase, so
24+
careful co-ordination is needed in adopting the rule to avoid
25+
creating merge issues for other PRs. */
26+
"dot-notation": "off",
27+
"indent": "off",
28+
"no-multi-spaces": "off",
29+
"no-unused-vars": "off",
30+
"object-curly-spacing": "off",
31+
"quote-props": "off"
32+
},
33+
"overrides": [
34+
{
35+
/* Code within /src is restricted to using ES5 JavaScript
36+
The exception is that ES6 classes are used sparingly - see exceptions below. */
37+
"files": ["./src/**/*.js"],
38+
39+
"parserOptions": {
40+
"sourceType": "script",
41+
"ecmaVersion": 5
42+
}
43+
},
44+
{
45+
/* These modules use ES6 classes, and so are parsed as ES6 to avoid errors. */
46+
"files": ["./src/core/**/a-*.js"],
47+
"parserOptions": {
48+
"ecmaVersion": 6
49+
}
50+
},
51+
{
52+
/* This module use ES6 classes, and so is parsed as ES6 to avoid errors. */
53+
"files": ["./src/extras/primitives/primitives.js"],
54+
"parserOptions": {
55+
"ecmaVersion": 6
56+
}
57+
},
58+
{
59+
/* This code is external, and the ES5 restrictions do not apply to it. */
60+
"files": ["./src/lib/**/*.js"],
61+
"parserOptions": {
62+
"sourceType": "module",
63+
"ecmaVersion": 12
64+
}
65+
}
66+
]
67+
}

examples/showcase/link-traversal/js/components/aframe-tooltip-component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,4 @@
369369

370370
/***/ })
371371
/******/ ]);
372-
/*eslint-enable */
372+
/* eslint-enable */

examples/showcase/ui/info-panel.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ AFRAME.registerComponent('info-panel', {
44
var buttonEls = document.querySelectorAll('.menu-button');
55
var fadeBackgroundEl = this.fadeBackgroundEl = document.querySelector('#fadeBackground');
66

7-
this.movieImageEl;
87
this.movieTitleEl = document.querySelector('#movieTitle');
98
this.movieDescriptionEl = document.querySelector('#movieDescription');
109

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"docs": "markserv --dir docs --port 9001",
1313
"preghpages": "node ./scripts/preghpages.js",
1414
"ghpages": "ghpages -p gh-pages/",
15-
"lint": "semistandard -v | snazzy",
16-
"lint:fix": "semistandard --fix",
15+
"lint": "standardx -v | snazzy",
16+
"lint:fix": "standardx --fix",
1717
"precommit": "npm run lint",
1818
"prepush": "node scripts/testOnlyCheck.js",
1919
"prerelease": "node scripts/release.js 1.4.1 1.4.2",
@@ -35,11 +35,11 @@
3535
"vendor/**/*"
3636
],
3737
"dependencies": {
38+
"@ungap/custom-elements": "^1.1.0",
3839
"buffer": "^6.0.3",
3940
"custom-event-polyfill": "^1.0.6",
4041
"debug": "ngokevin/debug#noTimestamp",
4142
"deep-assign": "^2.0.0",
42-
"@ungap/custom-elements": "^1.1.0",
4343
"load-bmfont": "^1.2.3",
4444
"object-assign": "^4.0.1",
4545
"present": "0.0.6",
@@ -58,6 +58,9 @@
5858
"chalk": "^1.1.3",
5959
"cross-env": "^7.0.3",
6060
"css-loader": "^6.7.1",
61+
"eslint": "^8.45.0",
62+
"eslint-config-semistandard": "^17.0.0",
63+
"eslint-config-standard-jsx": "^11.0.0",
6164
"ghpages": "0.0.8",
6265
"git-rev": "^0.2.1",
6366
"glob": "^8.0.3",
@@ -76,12 +79,12 @@
7679
"markserv": "github:sukima/markserv#feature/fix-broken-websoketio-link",
7780
"mocha": "^10.0.0",
7881
"replace-in-file": "^2.5.3",
79-
"semistandard": "^9.0.0",
8082
"shelljs": "^0.7.7",
8183
"shx": "^0.2.2",
8284
"sinon": "<12.0.0",
8385
"sinon-chai": "^3.7.0",
8486
"snazzy": "^5.0.0",
87+
"standardx": "^7.0.0",
8588
"style-loader": "^3.3.1",
8689
"too-wordy": "ngokevin/too-wordy",
8790
"webpack": "^5.73.0",
@@ -91,7 +94,7 @@
9194
"write-good": "^1.0.8"
9295
},
9396
"link": true,
94-
"semistandard": {
97+
"standardx": {
9598
"ignore": [
9699
"build/**",
97100
"dist/**",

scripts/docsLint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pages.forEach(function checkPage (pagePath) {
5151
}
5252

5353
// Unused defined links: `[page]: ../page.md -> [*][page]`
54-
let referenceRegex = new RegExp(`\\[\(\.\*\)\?\\]: \.\*`, 'g');
54+
let referenceRegex = new RegExp('\\[\(\.\*\)\?\\]: \.\*', 'g');
5555
match = referenceRegex.exec(content);
5656
while (match !== null) {
5757
referencingRegex = new RegExp(`\\[${match[1]}\\]`, 'g');

src/components/hand-tracking-controls.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,12 @@ module.exports.Component = registerComponent('hand-tracking-controls', {
183183
return function () {
184184
var jointPoses = this.jointPoses;
185185
var controller = this.el.components['tracked-controls'] && this.el.components['tracked-controls'].controller;
186-
var i = 0;
187186
if (!controller || !this.mesh) { return; }
188187
this.mesh.visible = false;
189188
if (!this.hasPoses) { return; }
190-
for (var inputjoint of controller.hand.values()) {
189+
var inputjoints = controller.hand.values();
190+
for (var i = 0; i < inputjoints.length; i++) {
191+
var inputjoint = inputjoints[i];
191192
var bone = this.getBone(inputjoint.jointName);
192193
if (bone != null) {
193194
this.mesh.visible = true;
@@ -341,4 +342,3 @@ module.exports.Component = registerComponent('hand-tracking-controls', {
341342
this.el.setObject3D('mesh', mesh);
342343
}
343344
});
344-

src/components/scene/ar-hit-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ module.exports.Component = register('ar-hit-test', {
436436
tempImageData = this.context.getImageData(0, 0, 512, 512);
437437
for (var i = 0; i < 512 * 512; i++) {
438438
// if it's a little bit transparent but not opaque make it middle transparent
439-
if (tempImageData.data[ i * 4 + 3 ] !== 0 && tempImageData.data[ i * 4 + 3 ] !== 255) {
440-
tempImageData.data[ i * 4 + 3 ] = 128;
439+
if (tempImageData.data[i * 4 + 3] !== 0 && tempImageData.data[i * 4 + 3] !== 255) {
440+
tempImageData.data[i * 4 + 3] = 128;
441441
}
442442
}
443443
this.context.putImageData(tempImageData, 0, 0);

src/components/scene/pool.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ module.exports.Component = registerComponent('pool', {
128128
return el;
129129
},
130130

131-
updateRaycasters () {
131+
updateRaycasters: function () {
132132
var raycasterEls = document.querySelectorAll('[raycaster]');
133133

134134
raycasterEls.forEach(function (el) {

src/core/a-cubemap.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,3 @@ class ACubeMap extends HTMLElement {
6161
}
6262

6363
customElements.define('a-cubemap', ACubeMap);
64-

src/lib/rStatsAframe.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ window.aframeStats = function (scene) {
99
caption: 'Load Time'
1010
}
1111
};
12-
var _groups = [ {
12+
var _groups = [{
1313
caption: 'A-Frame',
14-
values: [ 'te', 'lt' ]
15-
} ];
14+
values: ['te', 'lt']
15+
}];
1616

1717
function _update () {
1818
_rS('te').set(getEntityCount());

0 commit comments

Comments
 (0)