Bug 1881696 - Rework the ESLint environment so that eslint-plugin-mozilla is not enforcing the environment everywhere. r=frontend-codestyle-reviewers,Gijs

This makes it easier for subscribers of eslint-plugin-mozilla to use it more generally as a set of recommended
rules. The only environment definitions are for mozilla-specific file types, where we should be safe to specify
them.

Differential Revision: https://phabricator.services.mozilla.com/D225704
This commit is contained in:
Mark Banner
2024-10-18 09:21:27 +00:00
parent 9418512337
commit c68ca31462
3 changed files with 37 additions and 16 deletions

View File

@@ -54,6 +54,9 @@ module.exports = {
ignorePatterns,
// Ignore eslint configurations in parent directories.
root: true,
env: {
es2024: true,
},
// New rules and configurations should generally be added in
// tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js to
// allow external repositories that use the plugin to pick them up as well.
@@ -64,6 +67,27 @@ module.exports = {
],
plugins: ["mozilla", "html", "import", "json"],
overrides: [
{
files: ["*.*"],
// The browser environment is not available for system modules, sjs, workers
// or any of the xpcshell-test files.
excludedFiles: [
"*.sys.mjs",
"*.sjs",
"**/?(*.)worker.?(m)js",
...testPaths.xpcshell.map(filePath => `${filePath}**`),
],
env: {
browser: true,
},
},
{
files: ["*.*"],
env: {
"mozilla/privileged": true,
"mozilla/specific": true,
},
},
{
files: [
// All .eslintrc.js files are in the node environment, so turn that

View File

@@ -5,9 +5,17 @@
"use strict";
/**
* The configuration is based on eslint:recommended config. The details for all
* the ESLint rules, and which ones are in the recommended configuration can
* be found here:
* The configuration is based on eslint:recommended config. It defines the
* recommended rules for all files, as well as for rules relating to modules
* and other module like files.
*
* The configuration intentionally does not specify the globals for the
* majority of files. The globals will only be specified for Mozilla specific
* files (e.g. system modules). The subscriber to this configuration is expect
* to include the correct globals that they require in their project.
*
* The details for all the ESLint rules, and which ones are in the ESLint
* recommended configuration can be found here:
*
* https://eslint.org/docs/rules/
*
@@ -28,13 +36,6 @@
* - This doesn't reveal any actual errors, and is a lot of work to address.
*/
module.exports = {
env: {
browser: true,
es2022: true,
"mozilla/privileged": true,
"mozilla/specific": true,
},
// The prettier configuration here comes from eslint-config-prettier and
// turns off all of ESLint's rules related to formatting.
extends: ["eslint:recommended"],
@@ -45,7 +46,8 @@ module.exports = {
// so we turn that off for those. Though we do have our own special
// environment for them.
env: {
browser: false,
"mozilla/privileged": true,
"mozilla/specific": true,
"mozilla/sysmjs": true,
},
files: ["**/*.sys.mjs"],
@@ -101,10 +103,7 @@ module.exports = {
},
{
env: {
browser: false,
"mozilla/privileged": false,
"mozilla/sjs": true,
"mozilla/specific": false,
},
files: ["**/*.sjs"],
rules: {
@@ -115,7 +114,6 @@ module.exports = {
},
{
env: {
browser: false,
worker: true,
},
files: [

View File

@@ -3,7 +3,6 @@
module.exports = {
env: {
browser: false,
"mozilla/privileged": true,
"mozilla/xpcshell": true,
},