I have the following in eslint.config.js in my project:
import globals from "globals";
import pluginJs from "@eslint/js";
export default [{
languageOptions: {
globals: globals.browser
}
},
pluginJs.configs.recommended
];
I am working on a main script and a set of other scripts that provide globals.
The index.html imports the files like this:
<script src="js/module1.js"></script>
<script src="js/main.js"></script>
module1.js declares a global:
/* exported my_global */
const my_global = {}
With the configuration above, ESLint gives no-unused-vars error, and picks up a bunch of other errors based on strict rules.
If I change the config to the following:
import globals from "globals";
import pluginJs from "@eslint/js";
export default [{
languageOptions: {
globals: globals.browser,
sourceType: "module",
ecmaVersion: 5,
parseOptions: {
ecmaFeatures: {impliedStrict: false, globalReturn: false, jsx: false}
}
}
},
pluginJs.configs.recommended
];
Then ESLint shows no errors, ignoring the “exported” global and the various errors in main. I’ve tried impliedStrict: true and sourceType: “script” and the result is the same.
The way I read this documentation it says that these should have identical results, as the new config is just explicitly setting the defaults:
https://eslint.org/docs/latest/use/configure/language-options
Why are they not equivalent?
What I want is to be able to have ESLint generate errors using strict rules but be able to tell it I’m exporting a global so it doesn’t complain about that. I’ve tried the exported comment, “use_strict; and various combinations of config options but I’ve not been able to get the result.
I also asked an overlapping question here:
How do I configure ESLint in VS Code for JS module script