no-restricted-globals
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"no-restricted-globals": "error",
},
},
];/*global event, fdescribe*/
/*eslint no-restricted-globals: ["error", "event", "fdescribe"]*/
function onClick() {
console.log(event);
}
fdescribe("foo", function() {
});/*global event*/
/* eslint no-restricted-globals: ["error", { name: "event", message: "Use local parameter instead." }] */
function onClick() {
console.log(event); // Unexpected global variable 'event'. Use local parameter instead.
}/*global event, fdescribe*/
/*eslint no-restricted-globals: ["error", { globals: ["event", "fdescribe"] }]*/
function onClick() {
console.log(event);
}
fdescribe("foo", function() {
});/*global event*/
/*eslint no-restricted-globals: ["error", "event"]*/
import event from "event-module";/*global event*/
/*eslint no-restricted-globals: ["error", "event"]*/
const event = 1;const fetchData: Promise<string> = fetchString();
interface CustomEvent extends Event {}
class CustomWindow implements Window {}
function handleClick(event: Event) {
console.log(event);
}Examples from the ESLint documentation.
no-restricted-globals
eslint
export default [
{
rules: {
"no-restricted-globals": "error",
},
},
];no-restricted-globals
eslint plugin · restriction
{
"rules": {
"no-restricted-globals": "error"
}
}style/noRestrictedGlobals
style · since 1.0.0
{
"linter": {
"rules": {
"style": {
"noRestrictedGlobals": "error"
}
}
}
}Disallow assignment operators in return statements
Enforce variables to be declared either together or separately in functions
Require using Error objects as Promise rejection reasons
Disallow loops with a body that allows only one iteration