Skip to content

Commit

Permalink
Add & configure ESlint; incl. plugins
Browse files Browse the repository at this point in the history
Issue 2096
  • Loading branch information
robyngit committed May 14, 2024
1 parent f33bf9e commit 21c22b7
Show file tree
Hide file tree
Showing 3 changed files with 3,966 additions and 105 deletions.
57 changes: 57 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* global import */

import globals from "globals";
import pluginJs from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";
import path from "path";
import prettierConfig from "eslint-config-prettier";
import requirejs from "eslint-plugin-requirejs";
import { fileURLToPath } from "url";


// This chunk needed to use older style shared eslint configs, e.g. airbnb-base
// mimic CommonJS variables -- not needed if using CommonJS
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const compat = new FlatCompat({
baseDirectory: __dirname
});

export default [
// This object must contain no other properties than ignores in order for it
// to apply to all config objects in this array
{ ignores: ["src/components/"] },
// Use the recommended config for JS files
pluginJs.configs.recommended,
// Use the popular airbnb-base config, but extend it with our own rules
...compat.extends("airbnb-base"),
// Lint all the main MetacatUI files
{
name: "lint-views-models-and-collections",
files: ["src/**/*.js"],
plugins: {
requirejs
},
languageOptions: {
sourceType: "commonjs",
ecmaVersion: 2020,
globals: {
...globals.browser,
...globals.amd,
MetacatUI: "readonly",
}
},
// Use requirejs.configs.recommended.rules and some of our own rules
rules: {
...requirejs.configs.recommended.rules,
"import/no-amd": "off", // We use AMD
"no-console": "off", // We allow console.log for now
"strict": ["error", "global"], // We use strict mode
"func-names": "off", // require and backbone need to use unnamed functions
}

},
// Allow the prettier plugin to override any conflicting rules
...[].concat(prettierConfig),
];
Loading

0 comments on commit 21c22b7

Please sign in to comment.