Skip to content

Commit 0967ce6

Browse files
committed
REST: Improve ESLint config
* Lint all `repo/domain/` dirs and not just `tests/mocha/` * Extend sensible wikimedia configs * Don't specify `--config` arg in `packages.json` as not needed and ignores all other config files * Remove no-longer-needed REST API specific dirs from `.eslintignore` * Remove no-longer-needed config file * Use `.js` config files as they support comments * Fix linting issues in `.js` and `.json` files Change-Id: I00a65b2a13e2970250afabc9a729c56d494bae0f
1 parent a6a89bd commit 0967ce6

24 files changed

+181
-129
lines changed

.eslintignore

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
/client/data-bridge/
55
/lib/resources/wikibase-api/
66
/lib/packages/wikibase/*/tests/**/*.json
7-
/repo/rest-api/
8-
/repo/domains/crud/
97

108
# Build tooling
119
/docs/

repo/domains/crud/.eslintrc.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
/* eslint-disable quote-props, quotes */
4+
module.exports = {
5+
root: true,
6+
extends: [
7+
"wikimedia",
8+
"wikimedia/node",
9+
"wikimedia/language/es2022"
10+
],
11+
env: {
12+
"node": true
13+
},
14+
rules: {
15+
"camelcase": "off",
16+
"comma-dangle": "off",
17+
"max-len": [ "warn", { code: 130 } ],
18+
"no-implicit-coercion": [ "error", { disallowTemplateShorthand: true } ],
19+
"no-console": "error",
20+
"template-curly-spacing": 'off',
21+
},
22+
overrides: [
23+
{
24+
files: [ "*.json" ],
25+
rules: {
26+
"max-len": "off",
27+
}
28+
}
29+
]
30+
};

repo/domains/crud/specs/global/examples.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
}
3434
}
3535
},
36-
"DataPolicyViolationExample": {
36+
"DataPolicyViolationExample": {
3737
"value": {
38-
"code":"data-policy-violation",
39-
"message":"Edit violates data policy",
40-
"context":{
38+
"code": "data-policy-violation",
39+
"message": "Edit violates data policy",
40+
"context": {
4141
"violation": "{violation_code}",
4242
"violation_context": {
4343
"some": "context"
@@ -80,7 +80,7 @@
8080
"value": {
8181
"code": "referenced-resource-not-found",
8282
"message": "The referenced resource does not exist",
83-
"context": { "path": "{json_pointer}" }
83+
"context": { "path": "{json_pointer}" }
8484
}
8585
},
8686
"CannotModifyReadOnlyValue": {
@@ -106,7 +106,7 @@
106106
"code": "patch-test-failed",
107107
"message": "Test operation in the provided patch failed",
108108
"context": {
109-
"path": "{json_pointer_to_patch_operation}" ,
109+
"path": "{json_pointer_to_patch_operation}",
110110
"actual_value": "actual value"
111111
}
112112
}

repo/domains/crud/specs/global/responses.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@
790790
"id": "P694$B4C349A2-C504-4FC5-B7D5-8B781C719D71",
791791
"rank": "normal",
792792
"property": {
793-
"id":"P1628",
793+
"id": "P1628",
794794
"data_type": "url"
795795
},
796796
"value": {

repo/domains/crud/specs/global/schemas.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"additionalProperties": {
6060
"type": "string"
6161
}
62-
}, "Descriptions": {
62+
},
63+
"Descriptions": {
6364
"type": "object",
6465
"additionalProperties": {
6566
"type": "string"

repo/domains/crud/specs/resources/aliases/requests.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"AddAliasesInLanguage":{
2+
"AddAliasesInLanguage": {
33
"allOf": [
44
{
55
"type": "object",

repo/domains/crud/specs/resources/properties/requests.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"statements": {
4141
"P1628": [
4242
{
43-
"property": { "id":"P1628" },
43+
"property": { "id": "P1628" },
4444
"value": {
4545
"type": "value",
4646
"content": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"

repo/domains/crud/specs/resources/statements/examples.json

+15-15
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@
2727
}
2828
],
2929
"references": [
30-
{
31-
"hash": "7ccd777f870b71a4c5056c7fd2a83a22cc39be6d",
32-
"parts": [
33-
{
34-
"property": {
35-
"id": "P709",
36-
"data_type": "url"
37-
},
38-
"value": {
39-
"type": "value",
40-
"content": "https://news.example.org"
41-
}
30+
{
31+
"hash": "7ccd777f870b71a4c5056c7fd2a83a22cc39be6d",
32+
"parts": [
33+
{
34+
"property": {
35+
"id": "P709",
36+
"data_type": "url"
37+
},
38+
"value": {
39+
"type": "value",
40+
"content": "https://news.example.org"
4241
}
43-
]
44-
}
45-
]
42+
}
43+
]
44+
}
45+
]
4646
},
4747
"PropertyStatementResponse": {
4848
"id": "P694$B4C349A2-C504-4FC5-B7D5-8B781C719D71",

repo/domains/crud/specs/resources/statements/responses.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@
355355
"id": "P694$B4C349A2-C504-4FC5-B7D5-8B781C719D71",
356356
"rank": "normal",
357357
"property": {
358-
"id":"P1628",
358+
"id": "P1628",
359359
"data_type": "url"
360360
},
361361
"value": {
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
/* eslint-disable quotes */
4+
module.exports = {
5+
extends: [
6+
"wikimedia/mocha"
7+
],
8+
ignorePatterns: [
9+
".test-user-credentials.json"
10+
],
11+
rules: {
12+
"no-unused-expressions": "off",
13+
"prefer-arrow-callback": "off",
14+
"mocha/no-setup-in-describe": 0,
15+
"mocha/no-skipped-tests": "error"
16+
}
17+
};

repo/domains/crud/tests/mocha/.eslintrc.json

-26
This file was deleted.

repo/domains/crud/tests/mocha/helpers/RequestBuilderFactory.js

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const { RequestBuilder } = require( '../../../../../rest-api/tests/mocha/helpers
44
const { getAllowedBadges } = require( './getAllowedBadges' );
55

66
async function badgesConfig() {
7-
// eslint-disable-next-line es-x/no-object-fromentries
87
return { badgeItems: Object.fromEntries( // TODO fix eslint config to allow this
98
( await getAllowedBadges() ).map( ( badge ) => [ badge, '' ] )
109
) };

repo/domains/search/.eslintrc.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
/* eslint-disable quote-props, quotes */
4+
module.exports = {
5+
root: true,
6+
extends: [
7+
"wikimedia",
8+
"wikimedia/node",
9+
"wikimedia/language/es2022"
10+
],
11+
env: {
12+
"node": true
13+
},
14+
rules: {
15+
"camelcase": "off",
16+
"comma-dangle": "off",
17+
"max-len": [ "warn", { code: 130 } ],
18+
"no-implicit-coercion": [ "error", { disallowTemplateShorthand: true } ],
19+
"no-console": "error",
20+
"template-curly-spacing": 'off',
21+
},
22+
overrides: [
23+
{
24+
files: [ "*.json" ],
25+
rules: {
26+
"max-len": "off",
27+
}
28+
}
29+
]
30+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
/* eslint-disable quotes */
4+
module.exports = {
5+
extends: [
6+
"wikimedia/mocha"
7+
],
8+
rules: {
9+
"no-unused-expressions": "off",
10+
"prefer-arrow-callback": "off",
11+
"mocha/no-setup-in-describe": 0,
12+
"mocha/no-skipped-tests": "error",
13+
}
14+
};

repo/domains/search/tests/mocha/.eslintrc.json

-26
This file was deleted.

repo/rest-api/.eslintrc.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
/* eslint-disable quote-props, quotes */
4+
module.exports = {
5+
root: true,
6+
extends: [
7+
"wikimedia",
8+
"wikimedia/node",
9+
"wikimedia/language/es2022"
10+
],
11+
env: {
12+
node: true,
13+
},
14+
ignorePatterns: [
15+
"node_modules/",
16+
"vendor",
17+
"dist/",
18+
"docs/",
19+
".redocly.lint-ignore.yaml",
20+
21+
// auto-generated openapi files
22+
"specs/openapi-joined.json",
23+
"src/openapi.json"
24+
],
25+
rules: {
26+
"max-len": [ "warn", { "code": 130 } ],
27+
"no-unused-expressions": "off",
28+
"prefer-arrow-callback": "off",
29+
"template-curly-spacing": "off",
30+
"camelcase": "off",
31+
"comma-dangle": "off",
32+
"no-implicit-coercion": [ "error", { "disallowTemplateShorthand": true } ]
33+
},
34+
overrides: [
35+
{
36+
files: [ "*.json" ],
37+
rules: {
38+
"max-len": "off",
39+
}
40+
}
41+
]
42+
};

repo/rest-api/.eslintrc.json

-20
This file was deleted.

repo/rest-api/.mocharc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint no-undef:0 */ // it's confused about "module" and "process" because .eslintrc doesn't extend wikimedia/server
1+
'use strict';
22

33
module.exports = {
44
parallel: true,

repo/rest-api/package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
"mocha": "mocha --timeout 0 --inline-diffs",
1414
"lint": "npm-run-all --parallel lint:*",
1515
"lint:openapi": "npm run spec:join && redocly lint specs/openapi-joined.json",
16-
"lint:eslint": "eslint . --config .eslintrc.json --max-warnings 0",
17-
"lint:eslint-crud": "eslint ../domains/crud/tests/mocha --config ../domains/crud/tests/mocha/.eslintrc.json --max-warnings 0",
18-
"lint:eslint-search": "eslint ../domains/search/tests/mocha --config ../domains/search/tests/mocha/.eslintrc.json --max-warnings 0",
16+
"lint:eslint": "eslint . --max-warnings 0",
17+
"lint:eslint-crud": "eslint ../domains/crud --max-warnings 0",
18+
"lint:eslint-search": "eslint ../domains/search --max-warnings 0",
1919
"fix": "npm-run-all --parallel fix:*",
20-
"fix:eslint": "eslint --config .eslintrc.json --fix .",
21-
"fix:crud": "eslint ../domains/crud/tests/mocha --config ../domains/crud/tests/mocha/.eslintrc.json --fix",
22-
"fix:search": "eslint ../domains/search/tests/mocha --config ../domains/search/tests/mocha/.eslintrc.json --fix",
20+
"fix:eslint": "eslint --fix .",
21+
"fix:crud": "eslint ../domains/crud --fix",
22+
"fix:search": "eslint ../domains/search --fix",
2323
"build": "run-s build:spec build:docs",
2424
"build:docs": "webpack --config docs/webpack.config.js",
2525
"serve:docs": "webpack serve --config docs/webpack.config.js --mode development",

repo/rest-api/redocly/.eslintrc.json

-7
This file was deleted.

repo/rest-api/redocly/plugin-filter-schemas.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const path = require( 'path' );
77
function findSchemasFiles() {
88
const domainsPath = path.join( __dirname, '../../domains' );
99
if ( !fs.existsSync( domainsPath ) ) {
10-
throw new Error( `Domains directory not found at: ${ domainsPath}` );
10+
throw new Error( `Domains directory not found at: ${domainsPath}` );
1111
}
1212

1313
const schemaFiles = [];

repo/rest-api/specs/openapi.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
}
4444
}
4545
},
46-
"components": { },
46+
"components": {},
4747
"tags": [
4848
{
4949
"name": "OpenAPI document",

0 commit comments

Comments
 (0)