Skip to content

Commit 0a6f1c8

Browse files
committed
Harden lint configs
1 parent 38d7998 commit 0a6f1c8

File tree

139 files changed

+3548
-464
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+3548
-464
lines changed

eslint.config.js

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended"
55

66
export default defineConfig([
77
{
8-
files: ["**/*.{js,mjs,cjs}"],
8+
files: ["./src/**/*.{js,mjs,cjs}"],
99
languageOptions: {
1010
ecmaVersion: "latest",
1111
sourceType: "module",
@@ -16,11 +16,101 @@ export default defineConfig([
1616
},
1717
plugins: { js },
1818
extends: ["js/recommended"],
19-
ignores: ["**/*.spec.js"],
20-
},
21-
{
22-
files: ["**/*.{js,mjs,cjs}"],
23-
languageOptions: { globals: globals.browser },
19+
rules: {
20+
// ===== Code style =====
21+
indent: ["error", 2],
22+
quotes: ["error", "single"],
23+
semi: ["error", "always"],
24+
"comma-dangle": ["error", "never"],
25+
"comma-spacing": ["error", { before: false, after: true }],
26+
"space-before-function-paren": ["error", "always"],
27+
"space-in-parens": ["error", "never"],
28+
"space-infix-ops": "error",
29+
"object-curly-spacing": ["error", "always"],
30+
"array-bracket-spacing": ["error", "never"],
31+
"arrow-spacing": ["error", { before: true, after: true }],
32+
"block-spacing": "error",
33+
"brace-style": ["error", "1tbs", { allowSingleLine: false }],
34+
"max-len": [
35+
"error",
36+
{ code: 100, ignoreComments: false, ignoreStrings: false },
37+
],
38+
39+
// ===== Best practices =====
40+
"no-var": "error",
41+
"prefer-const": "error",
42+
eqeqeq: ["error", "always"],
43+
curly: ["error", "all"],
44+
"no-console": ["error"],
45+
"no-debugger": "error",
46+
"no-alert": "error",
47+
"no-eval": "error",
48+
"no-duplicate-imports": "error",
49+
"no-unused-vars": [
50+
"error",
51+
{ args: "after-used", ignoreRestSiblings: false },
52+
],
53+
"no-implicit-globals": "error",
54+
"no-magic-numbers": [
55+
"warn",
56+
{ ignore: [0, 1, -1], ignoreArrayIndexes: true, enforceConst: true },
57+
],
58+
"no-empty-function": "error",
59+
"no-fallthrough": "error",
60+
"no-invalid-this": "error",
61+
"no-return-assign": "error",
62+
"no-self-assign": "error",
63+
"no-self-compare": "error",
64+
"no-shadow": "error",
65+
"no-useless-catch": "error",
66+
"no-useless-return": "error",
67+
68+
// ===== Modern JS =====
69+
"prefer-arrow-callback": "error",
70+
"prefer-template": "error",
71+
"prefer-exponentiation-operator": "error",
72+
"prefer-destructuring": ["error", { object: true, array: false }],
73+
"object-shorthand": ["error", "always"],
74+
"arrow-body-style": ["error", "as-needed"],
75+
"no-useless-constructor": "error",
76+
77+
// ===== Readability & organization =====
78+
"newline-per-chained-call": ["error", { ignoreChainWithDepth: 1 }],
79+
"padding-line-between-statements": [
80+
"error",
81+
{ blankLine: "always", prev: "*", next: "return" },
82+
{ blankLine: "always", prev: ["const", "let", "var"], next: "*" },
83+
{ blankLine: "always", prev: "*", next: "if" },
84+
{ blankLine: "always", prev: "*", next: "for" },
85+
{ blankLine: "always", prev: "*", next: "while" },
86+
{ blankLine: "always", prev: "*", next: "try" },
87+
],
88+
"lines-between-class-members": [
89+
"error",
90+
"always",
91+
{ exceptAfterSingleLine: true },
92+
],
93+
"max-classes-per-file": ["error", 1],
94+
"consistent-return": "error",
95+
"dot-notation": "error",
96+
"id-length": ["warn", { min: 2, exceptions: ["i", "j"] }],
97+
"sort-imports": [
98+
"error",
99+
{
100+
ignoreCase: false,
101+
ignoreDeclarationSort: false,
102+
memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
103+
},
104+
],
105+
"newline-before-return": "error",
106+
107+
// ===== Security & safety =====
108+
"no-prototype-builtins": "error",
109+
"no-new-object": "error",
110+
"no-new-func": "error",
111+
"no-with": "error",
112+
},
113+
ignores: ["**/*.spec.js", "**/*.test.js"],
24114
},
25115
eslintPluginPrettierRecommended,
26116
]);

src/angular.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { $injectTokens as $t } from "./injection-tokens.js";
2222
import { annotate } from "./core/di/di.js";
2323

2424
const ngMinErr = minErr("ng");
25+
2526
const $injectorMinErr = minErr("$injector");
2627

2728
/** @type {Object.<string, NgModule>} */
@@ -64,7 +65,7 @@ export class Angular {
6465
this.errorHandlingConfig = errorHandlingConfig;
6566
this.$t = $t;
6667

67-
window["angular"] = this;
68+
window.angular = this;
6869
registerNgModule(this);
6970
}
7071

@@ -117,9 +118,11 @@ export class Angular {
117118
*/
118119
module(name, requires, configFn) {
119120
assertNotHasOwnProperty(name, "module");
121+
120122
if (requires && hasOwn(modules, name)) {
121123
modules[name] = null; // force ensure to recreate the module
122124
}
125+
123126
return ensure(modules, name, () => {
124127
if (!requires) {
125128
throw $injectorMinErr(
@@ -128,6 +131,7 @@ export class Angular {
128131
name,
129132
);
130133
}
134+
131135
return new NgModule(name, requires, configFn);
132136
});
133137
}
@@ -204,6 +208,7 @@ export class Angular {
204208
this.bootsrappedModules.unshift("ng");
205209

206210
const injector = createInjector(this.bootsrappedModules, config.strictDi);
211+
207212
injector.invoke([
208213
$t.$rootScope,
209214
$t.$rootElement,
@@ -223,6 +228,7 @@ export class Angular {
223228
setCacheData(el, "$injector", $injector);
224229

225230
const compileFn = compile(el);
231+
226232
compileFn(scope);
227233

228234
// https://github.com/angular-ui/ui-router/issues/3678
@@ -251,6 +257,7 @@ export class Angular {
251257
);
252258
},
253259
]);
260+
254261
return injector;
255262
}
256263

@@ -268,11 +275,15 @@ export class Angular {
268275
*/
269276
init(element) {
270277
let appElement;
278+
271279
let module;
280+
272281
const config = {};
282+
273283
// The element `element` has priority over any other element.
274284
ngAttrPrefixes.forEach((prefix) => {
275285
const name = `${prefix}app`;
286+
276287
if (
277288
/** @type {Element} */ (element).hasAttribute &&
278289
/** @type {Element} */ (element).hasAttribute(name)
@@ -283,6 +294,7 @@ export class Angular {
283294
});
284295
ngAttrPrefixes.forEach((prefix) => {
285296
const name = `${prefix}app`;
297+
286298
let candidate;
287299

288300
if (
@@ -293,6 +305,7 @@ export class Angular {
293305
module = candidate.getAttribute(name);
294306
}
295307
});
308+
296309
if (appElement) {
297310
config.strictDi = getNgAttribute(appElement, "strict-di") !== null;
298311
this.bootstrap(appElement, module ? [module] : [], config);
@@ -312,6 +325,7 @@ export class Angular {
312325
*/
313326
getScopeByName(name) {
314327
const scope = this.$rootScope.$searchByName(name);
328+
315329
if (scope) {
316330
return scope.$proxy;
317331
}

src/animations/animate-cache.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const KEY = "$animId";
2+
23
let parentCounter = 0;
4+
35
const cache = new Map();
46

57
export function animateCache() {
@@ -14,10 +16,15 @@ export function animateCache() {
1416
*/
1517
cacheKey(node, method, addClass, removeClass) {
1618
const { parentNode } = node;
19+
1720
const parentID = parentNode[KEY] ?? (parentNode[KEY] = ++parentCounter);
21+
1822
const parts = [parentID, method, node.getAttribute("class")];
23+
1924
if (addClass) parts.push(addClass);
25+
2026
if (removeClass) parts.push(removeClass);
27+
2128
return parts.join(" ");
2229
},
2330

@@ -28,6 +35,7 @@ export function animateCache() {
2835
*/
2936
containsCachedAnimationWithoutDuration(key) {
3037
const entry = cache.get(key);
38+
3139
return entry ? !entry.isValid : false;
3240
},
3341

@@ -65,6 +73,7 @@ export function animateCache() {
6573
*/
6674
put(key, value, isValid) {
6775
const entry = cache.get(key);
76+
6877
if (entry) {
6978
entry.total++;
7079
entry.value = value;

src/animations/animate-children-directive.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ $$AnimateChildrenDirective.$inject = [$t.$interpolate];
1212
export function $$AnimateChildrenDirective($interpolate) {
1313
return {
1414
link(scope, element, attrs) {
15-
const val = attrs["ngAnimateChildren"];
15+
const val = attrs.ngAnimateChildren;
16+
1617
if (isString(val) && val.length === 0) {
1718
// empty attribute
1819
setCacheData(element, NG_ANIMATE_CHILDREN_DATA, true);

src/animations/animate-css-driver.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { AnimateRunner } from "./runner/animate-runner.js";
33
import { concatWithSpace } from "./shared.js";
44

55
const NG_ANIMATE_SHIM_CLASS_NAME = "ng-animate-shim";
6+
67
const NG_ANIMATE_ANCHOR_CLASS_NAME = "ng-anchor";
78

89
const NG_OUT_ANCHOR_CLASS_NAME = "ng-anchor-out";
10+
911
const NG_IN_ANCHOR_CLASS_NAME = "ng-anchor-in";
1012

1113
AnimateCssDriverProvider.$inject = ["$$animationProvider"];
@@ -30,6 +32,7 @@ export function AnimateCssDriverProvider($$animationProvider) {
3032
*/
3133
function ($animateCss, $rootElement) {
3234
const bodyNode = document.body;
35+
3336
const rootNode = $rootElement;
3437

3538
const rootBodyElement =
@@ -52,6 +55,7 @@ export function AnimateCssDriverProvider($$animationProvider) {
5255

5356
function prepareAnchoredAnimation(outAnchor, inAnchor) {
5457
const clone = outAnchor.cloneNode(true);
58+
5559
const startingClasses = filterCssClasses(getClassVal(clone));
5660

5761
outAnchor[0].classList.add(NG_ANIMATE_SHIM_CLASS_NAME);
@@ -62,6 +66,7 @@ export function AnimateCssDriverProvider($$animationProvider) {
6266
rootBodyElement.append(clone);
6367

6468
let animatorIn;
69+
6570
const animatorOut = prepareOutAnimation();
6671

6772
// the user may not end up using the `out` animation and
@@ -70,6 +75,7 @@ export function AnimateCssDriverProvider($$animationProvider) {
7075
// animation is over unless both animations are not used.
7176
if (!animatorOut) {
7277
animatorIn = prepareInAnimation();
78+
7379
if (!animatorIn) {
7480
return end();
7581
}
@@ -82,17 +88,21 @@ export function AnimateCssDriverProvider($$animationProvider) {
8288
let runner;
8389

8490
let currentAnimation = startingAnimator.start();
91+
8592
currentAnimation.done(() => {
8693
currentAnimation = null;
94+
8795
if (!animatorIn) {
8896
animatorIn = prepareInAnimation();
97+
8998
if (animatorIn) {
9099
currentAnimation = animatorIn.start();
91100
currentAnimation.done(() => {
92101
currentAnimation = null;
93102
end();
94103
runner.complete();
95104
});
105+
96106
return currentAnimation;
97107
}
98108
}
@@ -125,6 +135,7 @@ export function AnimateCssDriverProvider($$animationProvider) {
125135
// all the keys for the coords object when iterated
126136
["width", "height", "top", "left"].forEach((key) => {
127137
let value = coords[key];
138+
128139
switch (key) {
129140
case "top":
130141
value += bodyNode.scrollTop;
@@ -135,6 +146,7 @@ export function AnimateCssDriverProvider($$animationProvider) {
135146
}
136147
styles[key] = `${Math.floor(value)}px`;
137148
});
149+
138150
return styles;
139151
}
140152

@@ -156,7 +168,9 @@ export function AnimateCssDriverProvider($$animationProvider) {
156168

157169
function prepareInAnimation() {
158170
const endingClasses = filterCssClasses(getClassVal(inAnchor));
171+
159172
const toAdd = getUniqueValues(endingClasses, startingClasses);
173+
160174
const toRemove = getUniqueValues(startingClasses, endingClasses);
161175

162176
const animator = $animateCss(clone, {
@@ -180,13 +194,18 @@ export function AnimateCssDriverProvider($$animationProvider) {
180194

181195
function prepareFromToAnchorAnimation(from, to, anchors) {
182196
const fromAnimation = prepareRegularAnimation(from);
197+
183198
const toAnimation = prepareRegularAnimation(to);
184199

185200
const anchorAnimations = [];
201+
186202
anchors.forEach((anchor) => {
187203
const outElement = anchor.out;
204+
188205
const inElement = anchor.in;
206+
189207
const animator = prepareAnchoredAnimation(outElement, inElement);
208+
190209
if (animator) {
191210
anchorAnimations.push(animator);
192211
}
@@ -278,6 +297,8 @@ function filterCssClasses(classes) {
278297

279298
function getUniqueValues(a, b) {
280299
if (isString(a)) a = a.split(" ");
300+
281301
if (isString(b)) b = b.split(" ");
302+
282303
return a.filter((val) => b.indexOf(val) === -1).join(" ");
283304
}

0 commit comments

Comments
 (0)