Skip to content

Commit a68c20e

Browse files
authored
Update ESLint and simplify its configs (#568)
* refactor: Convert ESLint config files to YAML This allows for the config files to be commented. * chore: Update eslint to v4 * refactor: Add a root tsconfig.json As the individual package tsconfigs can extend the root, this allows for common options to be centrally controlled, as well as making it easier to enable dev tools to be automatically properly configured. * style: Satisfy updated lint rules * refactor: Merge ESLint configs into .eslintrc.yaml & eslint-base.yaml * refactor: Move @babel/eslint-parser dependency & config to fluent-react
1 parent d874a75 commit a68c20e

Some content is hidden

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

41 files changed

+3455
-1964
lines changed

.eslintrc.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
root: true
2+
3+
env:
4+
es6: true
5+
6+
overrides:
7+
- files: ["*/src/*.js"]
8+
extends:
9+
- ./eslint-base.yaml
10+
parserOptions:
11+
ecmaVersion: 9
12+
sourceType: module
13+
14+
- files: ["*/src/*.ts"]
15+
parser: "@typescript-eslint/parser"
16+
parserOptions:
17+
project: ./tsconfig.json
18+
extends:
19+
- eslint:recommended
20+
- ./eslint-base.yaml
21+
- plugin:@typescript-eslint/recommended
22+
- plugin:@typescript-eslint/recommended-requiring-type-checking
23+
rules:
24+
complexity: off
25+
prefer-const: off
26+
no-undef: off
27+
no-unused-vars: [error, args: none]
28+
no-use-before-define: off
29+
"@typescript-eslint/no-inferrable-types": off
30+
"@typescript-eslint/no-unused-vars": [error, args: none]
31+
"@typescript-eslint/no-use-before-define": off
32+
"@typescript-eslint/explicit-function-return-type": error
33+
34+
- files: ["*/test/**"]
35+
parserOptions:
36+
ecmaVersion: 2020 # Required by import.meta
37+
sourceType: module
38+
env:
39+
node: true
40+
mocha: true
41+
plugins:
42+
- mocha
43+
rules:
44+
mocha/no-exclusive-tests: error
45+
mocha/no-identical-title: error

eslint-base.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
rules:
2+
valid-typeof: 2
3+
no-console: 1
4+
no-dupe-args: 2
5+
no-dupe-keys: 2
6+
no-duplicate-case: 2
7+
no-extra-semi: 1
8+
no-func-assign: 2
9+
func-call-spacing: [2, never]
10+
no-unreachable: 1
11+
no-unexpected-multiline: 2
12+
no-sparse-arrays: 2
13+
dot-location: [2, property]
14+
no-implied-eval: 2
15+
no-loop-func: 2
16+
no-useless-call: 2
17+
no-useless-concat: 2
18+
no-delete-var: 2
19+
no-shadow: 2
20+
no-undef: 2
21+
no-undef-init: 2
22+
no-unused-vars: 1
23+
consistent-return: 1
24+
curly: [2, multi-line]
25+
eqeqeq: 2
26+
no-extend-native: 2
27+
no-global-assign: 2
28+
no-extra-bind: 2
29+
array-bracket-spacing: 2
30+
brace-style: [1, 1tbs]
31+
no-mixed-spaces-and-tabs: 2
32+
no-tabs: 2
33+
prefer-arrow-callback: 1
34+
prefer-template: 2
35+
prefer-spread: 2
36+
quotes: [2, double, avoidEscape: true]
37+
max-depth: [2, 6]
38+
max-len: [2, 80]
39+
no-nested-ternary: 2
40+
no-unneeded-ternary: 2
41+
strict: [2, global]
42+
indent: [2, 2, SwitchCase: 1]
43+
no-useless-escape: 2
44+
no-duplicate-imports: 2
45+
no-unsafe-negation: 2
46+
no-use-before-define: [2, { functions: false, classes: false }]
47+
space-infix-ops: 2
48+
no-constant-condition: [1, checkLoops: false]
49+
no-empty: 1
50+
use-isnan: 2
51+
dot-notation: 2
52+
no-caller: 2
53+
no-else-return: 2
54+
no-eval: 2
55+
no-implicit-globals: 2
56+
no-iterator: 2
57+
no-multi-spaces: 2
58+
no-multi-str: 2
59+
no-octal: 2
60+
no-proto: 2
61+
no-sequences: 2
62+
block-spacing: 2
63+
eol-last: 2
64+
key-spacing: 2
65+
no-trailing-spaces: 2
66+
prefer-rest-params: 2
67+
no-cond-assign: 2
68+
keyword-spacing: 2
69+
arrow-parens: [2, as-needed]
70+
no-useless-return: 2
71+
semi: 2
72+
spaced-comment: [2, always]

eslint_js.json

Lines changed: 0 additions & 132 deletions
This file was deleted.

eslint_test.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

eslint_ts.json

Lines changed: 0 additions & 27 deletions
This file was deleted.

fluent-bundle/makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ GLOBAL := FluentBundle
44
include ../common.mk
55

66
lint:
7-
@$(ESLINT) --config $(ROOT)/eslint_ts.json --max-warnings 0 src/*.ts
8-
@$(ESLINT) --config $(ROOT)/eslint_test.json --max-warnings 0 test/
7+
@$(ESLINT) --max-warnings 0 src/ test/
98
@echo -e " $(OK) lint"
109

1110
.PHONY: compile

fluent-bundle/src/builtins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function values(
2222
opts: Record<string, FluentValue>,
2323
allowed: Array<string>
2424
): Record<string, unknown> {
25-
const unwrapped: Record<string, unknown> = Object.create(null);
25+
const unwrapped = Object.create(null) as Record<string, unknown>;
2626
for (const [name, opt] of Object.entries(opts)) {
2727
if (allowed.includes(name)) {
2828
unwrapped[name] = opt.valueOf();

fluent-bundle/src/bundle.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ export class FluentBundle {
2222
public _functions: Record<string, FluentFunction>;
2323
public _useIsolating: boolean;
2424
public _transform: TextTransform;
25-
public _intls: WeakMap<object, Record<string, object>> = new WeakMap();
25+
public _intls = new WeakMap<
26+
| typeof Intl.NumberFormat
27+
| typeof Intl.DateTimeFormat
28+
| typeof Intl.PluralRules,
29+
Record<string, Intl.NumberFormat | Intl.DateTimeFormat | Intl.PluralRules>
30+
>();
2631

2732
/**
2833
* Create an instance of `FluentBundle`.

fluent-bundle/src/resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function getArguments(
111111
args: Array<Expression | NamedArgument>
112112
): Arguments {
113113
const positional: Array<FluentValue> = [];
114-
const named: Record<string, FluentValue> = Object.create(null);
114+
const named = Object.create(null) as Record<string, FluentValue>;
115115

116116
for (const arg of args) {
117117
if (arg.type === "narg") {

fluent-bundle/src/resource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class FluentResource {
179179
}
180180

181181
function parseAttributes(): Record<string, Pattern> {
182-
let attrs: Record<string, Pattern> = Object.create(null);
182+
let attrs = Object.create(null) as Record<string, Pattern>;
183183

184184
while (test(RE_ATTRIBUTE_START)) {
185185
let name = match1(RE_ATTRIBUTE_START);

fluent-bundle/src/scope.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,27 @@ export class Scope {
3434
this.errors.push(error);
3535
}
3636

37-
memoizeIntlObject<ObjectT extends object, OptionsT>(
38-
ctor: new (locales: Array<string>, opts: OptionsT) => ObjectT,
39-
opts: OptionsT
40-
): ObjectT {
37+
memoizeIntlObject(
38+
ctor: typeof Intl.NumberFormat,
39+
opts: Intl.NumberFormatOptions
40+
): Intl.NumberFormat;
41+
memoizeIntlObject(
42+
ctor: typeof Intl.DateTimeFormat,
43+
opts: Intl.DateTimeFormatOptions
44+
): Intl.DateTimeFormat;
45+
memoizeIntlObject(
46+
ctor: typeof Intl.PluralRules,
47+
opts: Intl.PluralRulesOptions
48+
): Intl.PluralRules;
49+
memoizeIntlObject(
50+
ctor:
51+
| typeof Intl.NumberFormat
52+
| typeof Intl.DateTimeFormat
53+
| typeof Intl.PluralRules,
54+
opts: Intl.NumberFormatOptions &
55+
Intl.DateTimeFormatOptions &
56+
Intl.PluralRulesOptions
57+
): Intl.NumberFormat | Intl.DateTimeFormat | Intl.PluralRules {
4158
let cache = this.bundle._intls.get(ctor);
4259
if (!cache) {
4360
cache = {};
@@ -47,6 +64,6 @@ export class Scope {
4764
if (!cache[id]) {
4865
cache[id] = new ctor(this.bundle.locales, opts);
4966
}
50-
return cache[id] as ObjectT;
67+
return cache[id];
5168
}
5269
}

0 commit comments

Comments
 (0)