Skip to content

Commit 21c22b7

Browse files
committed
Add & configure ESlint; incl. plugins
Issue 2096
1 parent f33bf9e commit 21c22b7

File tree

3 files changed

+3966
-105
lines changed

3 files changed

+3966
-105
lines changed

eslint.config.mjs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* global import */
2+
3+
import globals from "globals";
4+
import pluginJs from "@eslint/js";
5+
import { FlatCompat } from "@eslint/eslintrc";
6+
import path from "path";
7+
import prettierConfig from "eslint-config-prettier";
8+
import requirejs from "eslint-plugin-requirejs";
9+
import { fileURLToPath } from "url";
10+
11+
12+
// This chunk needed to use older style shared eslint configs, e.g. airbnb-base
13+
// mimic CommonJS variables -- not needed if using CommonJS
14+
const __filename = fileURLToPath(import.meta.url);
15+
const __dirname = path.dirname(__filename);
16+
17+
const compat = new FlatCompat({
18+
baseDirectory: __dirname
19+
});
20+
21+
export default [
22+
// This object must contain no other properties than ignores in order for it
23+
// to apply to all config objects in this array
24+
{ ignores: ["src/components/"] },
25+
// Use the recommended config for JS files
26+
pluginJs.configs.recommended,
27+
// Use the popular airbnb-base config, but extend it with our own rules
28+
...compat.extends("airbnb-base"),
29+
// Lint all the main MetacatUI files
30+
{
31+
name: "lint-views-models-and-collections",
32+
files: ["src/**/*.js"],
33+
plugins: {
34+
requirejs
35+
},
36+
languageOptions: {
37+
sourceType: "commonjs",
38+
ecmaVersion: 2020,
39+
globals: {
40+
...globals.browser,
41+
...globals.amd,
42+
MetacatUI: "readonly",
43+
}
44+
},
45+
// Use requirejs.configs.recommended.rules and some of our own rules
46+
rules: {
47+
...requirejs.configs.recommended.rules,
48+
"import/no-amd": "off", // We use AMD
49+
"no-console": "off", // We allow console.log for now
50+
"strict": ["error", "global"], // We use strict mode
51+
"func-names": "off", // require and backbone need to use unnamed functions
52+
}
53+
54+
},
55+
// Allow the prettier plugin to override any conflicting rules
56+
...[].concat(prettierConfig),
57+
];

0 commit comments

Comments
 (0)