Skip to content

Commit

Permalink
refactor: switch to eslint flat config (#121)
Browse files Browse the repository at this point in the history
* refactor: switch to eslint flat config

* remove .eslintignore
  • Loading branch information
mdjermanovic committed Mar 18, 2024
1 parent 6f95a94 commit 59b1606
Show file tree
Hide file tree
Showing 35 changed files with 133 additions and 175 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

30 changes: 0 additions & 30 deletions .eslintrc.cjs

This file was deleted.

38 changes: 0 additions & 38 deletions Makefile.js
Expand Up @@ -4,9 +4,7 @@
* @copyright jQuery Foundation and other contributors, https://jquery.org/
* MIT License
*/
/* global echo, exec, exit, set, target */

/* eslint no-console: 0*/
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -40,15 +38,12 @@ const NODE = "node",

// Utilities - intentional extra space at the end of each string
MOCHA = `${NODE_MODULES}/mocha/bin/_mocha `,
ESLINT = `${NODE} ${NODE_MODULES}/eslint/bin/eslint `,

// If switching back to Istanbul when may be working with ESM
// ISTANBUL = `${NODE} ${NODE_MODULES}/istanbul/lib/cli.js `,
C8 = `${NODE} ${NODE_MODULES}/c8/bin/c8.js`,

// Files
MAKEFILE = "./Makefile.js",
JS_FILES = "lib/**/*.js",
TEST_FILES = "tests/*.js",
CJS_TEST_FILES = "tests/*.cjs";

Expand All @@ -60,39 +55,6 @@ target.all = function() {
target.test();
};

target.lint = function() {
let errors = 0,
lastReturn;

echo("Validating Makefile.js");
lastReturn = exec(ESLINT + MAKEFILE);
if (lastReturn.code !== 0) {
errors++;
}

echo("Validating JavaScript files");
lastReturn = exec(ESLINT + JS_FILES);
if (lastReturn.code !== 0) {
errors++;
}

echo("Validating JavaScript test files");
lastReturn = exec(ESLINT + TEST_FILES);
if (lastReturn.code !== 0) {
errors++;
}

echo("Validating CJS JavaScript test files");
lastReturn = exec(ESLINT + CJS_TEST_FILES);
if (lastReturn.code !== 0) {
errors++;
}

if (errors) {
exit(1);
}
};

target.test = function() {
let errors = 0;
let lastReturn = exec(`${NODE} ${MOCHA} -- -R progress -c ${CJS_TEST_FILES}`);
Expand Down
46 changes: 46 additions & 0 deletions eslint.config.js
@@ -0,0 +1,46 @@
import eslintConfigESLint from "eslint-config-eslint";
import globals from "globals";
import eslintPluginChaiFriendly from "eslint-plugin-chai-friendly";

export default [
{
ignores: [
"dist/",
"coverage/"
]
},
...eslintConfigESLint,
{
files: ["lib/**"],
rules: {
"no-underscore-dangle": "off"
}
},
{
files: ["tests/**"],
ignores: ["tests/util/**"],
languageOptions: {
globals: {
...globals.mocha
}
},
plugins: {
"chai-friendly": eslintPluginChaiFriendly
},
rules: {
"no-unused-expressions": "off",
"chai-friendly/no-unused-expressions": "error"
}
},
{
files: ["Makefile.js"],
languageOptions: {
globals: {
...globals.shelljs
}
},
rules: {
"no-console": "off"
}
}
];
1 change: 0 additions & 1 deletion lib/index.js
Expand Up @@ -45,7 +45,6 @@
* The main interface is the {@link analyze} function.
* @module escope
*/
/* eslint no-underscore-dangle: ["error", { "allow": ["__currentScope"] }] */

import assert from "assert";

Expand Down
7 changes: 4 additions & 3 deletions lib/pattern-visitor.js
Expand Up @@ -22,8 +22,6 @@
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/* eslint-disable no-undefined */

import estraverse from "estraverse";
import esrecurse from "esrecurse";

Expand All @@ -38,6 +36,9 @@ function getLast(xs) {
return xs[xs.length - 1] || null;
}

/**
* Visitor for destructuring patterns.
*/
class PatternVisitor extends esrecurse.Visitor {
static isPattern(node) {
const nodeType = node.type;
Expand Down Expand Up @@ -66,7 +67,7 @@ class PatternVisitor extends esrecurse.Visitor {

this.callback(pattern, {
topLevel: pattern === this.rootPattern,
rest: lastRestElement !== null && lastRestElement !== undefined && lastRestElement.argument === pattern,
rest: lastRestElement !== null && lastRestElement !== void 0 && lastRestElement.argument === pattern,
assignments: this.assignments
});
}
Expand Down
20 changes: 11 additions & 9 deletions lib/referencer.js
Expand Up @@ -22,9 +22,6 @@
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/* eslint-disable no-underscore-dangle */
/* eslint-disable no-undefined */

import estraverse from "estraverse";
import esrecurse from "esrecurse";
import Reference from "./reference.js";
Expand All @@ -51,7 +48,7 @@ function traverseIdentifierInPattern(options, rootPattern, referencer, callback)
visitor.visit(rootPattern);

// Process the right hand nodes recursively.
if (referencer !== null && referencer !== undefined) {
if (referencer !== null && referencer !== void 0) {
visitor.rightHandNodes.forEach(referencer.visit, referencer);
}
}
Expand All @@ -62,6 +59,9 @@ function traverseIdentifierInPattern(options, rootPattern, referencer, callback)
// FIXME: Now, we don't create module environment, because the context is
// implementation dependent.

/**
* Visitor for import specifiers.
*/
class Importer extends esrecurse.Visitor {
constructor(declaration, referencer) {
super(null, referencer.options);
Expand Down Expand Up @@ -108,7 +108,9 @@ class Importer extends esrecurse.Visitor {
}
}

// Referencing variables and creating bindings.
/**
* Referencing variables and creating bindings.
*/
class Referencer extends esrecurse.Visitor {
constructor(options, scopeManager) {
super(null, options);
Expand Down Expand Up @@ -432,7 +434,7 @@ class Referencer extends esrecurse.Visitor {
this.currentScope().__referencing(node);
}

// eslint-disable-next-line class-methods-use-this
// eslint-disable-next-line class-methods-use-this -- Desired as instance method
PrivateIdentifier() {

// Do nothing.
Expand Down Expand Up @@ -482,9 +484,9 @@ class Referencer extends esrecurse.Visitor {
this.visitProperty(node);
}

BreakStatement() {} // eslint-disable-line class-methods-use-this
BreakStatement() {} // eslint-disable-line class-methods-use-this -- Desired as instance method

ContinueStatement() {} // eslint-disable-line class-methods-use-this
ContinueStatement() {} // eslint-disable-line class-methods-use-this -- Desired as instance method

LabeledStatement(node) {
this.visit(node.body);
Expand Down Expand Up @@ -643,7 +645,7 @@ class Referencer extends esrecurse.Visitor {
this.visit(local);
}

MetaProperty() { // eslint-disable-line class-methods-use-this
MetaProperty() { // eslint-disable-line class-methods-use-this -- Desired as instance method

// do nothing.
}
Expand Down
6 changes: 2 additions & 4 deletions lib/scope-manager.js
Expand Up @@ -22,8 +22,6 @@
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/* eslint-disable no-underscore-dangle */

import {
BlockScope,
CatchScope,
Expand Down Expand Up @@ -180,9 +178,9 @@ class ScopeManager {
return null;
}

attach() { } // eslint-disable-line class-methods-use-this
attach() { } // eslint-disable-line class-methods-use-this -- Desired as instance method

detach() { } // eslint-disable-line class-methods-use-this
detach() { } // eslint-disable-line class-methods-use-this -- Desired as instance method

__nestScope(scope) {
if (scope instanceof GlobalScope) {
Expand Down

0 comments on commit 59b1606

Please sign in to comment.