forked from NCEAS/metacatui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
eslint.config.mjs
114 lines (107 loc) · 3.2 KB
/
eslint.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { FlatCompat } from "@eslint/eslintrc";
import path from "path";
import { fileURLToPath } from "url";
import globals from "globals";
import prettierConfig from "eslint-config-prettier";
import requirejs from "eslint-plugin-requirejs";
import jsdoc from "eslint-plugin-jsdoc";
// For compatibility with configs that don't use the new eslint flat config format:
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
});
// ---------------------------------------------------------------------
// AIRBNB JAVASCRIPT STYLE GUIDE:
// Use the Airbnb style guide, excluding react- and node- specific rules & the
// rule that disallows "use strict"
const airbnbConfigs = [
...compat.extends("eslint-config-airbnb-base/rules/best-practices"),
...compat.extends("eslint-config-airbnb-base/rules/errors"),
...compat.extends("eslint-config-airbnb-base/rules/style"),
...compat.extends("eslint-config-airbnb-base/rules/variables"),
...compat.extends("eslint-config-airbnb-base/rules/es6"),
...compat.extends("eslint-config-airbnb-base/rules/imports"),
];
const airbnbRulesOverrides = {
// We are using the AMD/RequireJS module pattern
"import/no-amd": "off",
"import/no-commonjs": "off",
// We are using RequireJS
"import/no-unresolved": "off",
// Allow unused variables if they start with an underscore
"variables/no-unused-vars": [
"error",
{
vars: "all",
args: "after-used",
ignoreRestSiblings: true,
varsIgnorePattern: "^_",
},
],
};
// ---------------------------------------------------------------------
// JSDOCS:
// Ensure JSDoc comments are used, and check validity
const jsdocConfig = jsdoc.configs["flat/recommended"];
const jsdocsRulesOverrides = {
// Non-standard JSDoc tags we use to generate documentation.
"jsdoc/check-tag-names": [
"error",
{ definedTags: ["classcategory", "screenshot"] },
],
// Avoiding this error would mean importing modules we don't use
"jsdoc/no-undefined-types": "off",
};
// ---------------------------------------------------------------------
// REQUIREJS:
// Use all rules from the recommended config for RequireJS
const requirejsConfig = {
name: "requirejs",
plugins: {
requirejs,
},
rules: {
...requirejs.configs.recommended.rules,
},
};
// ---------------------------------------------------------------------
// METACATUI OVERRIDES:
const metacatuiConfig = {
files: ["src/**/*.js"],
languageOptions: {
sourceType: "commonjs",
ecmaVersion: 2020,
globals: {
...globals.browser,
...globals.amd,
MetacatUI: "readonly",
google: "readonly",
},
},
// Override rules that are not compatible with MetacatUI
rules: {
...airbnbRulesOverrides,
...jsdocsRulesOverrides,
},
};
// Ignores must be a separate object to be treated as global
const ignoreList = {
ignores: [
"src/components/",
"docs/",
"test/",
"node_modules/",
".github",
"server.js",
"eslint.config.mjs",
],
};
export default [
ignoreList,
...airbnbConfigs,
jsdocConfig,
requirejsConfig,
metacatuiConfig,
prettierConfig, // prettier must be the last config in the array
];