Skip to content

Commit

Permalink
Update to ESLint 8
Browse files Browse the repository at this point in the history
  • Loading branch information
onigoetz committed Oct 14, 2021
1 parent 49acbe1 commit fdade2a
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 136 deletions.
2 changes: 1 addition & 1 deletion packages/crafty-preset-babel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"babel-loader": "8.2.2",
"gulp-babel": "8.0.0",
"gulp-concat": "2.6.1",
"gulp-eslint7": "0.3.2",
"gulp-eslint-new": "0.4.0",
"gulp-newer": "1.4.0",
"gulp-sourcemaps": "3.0.0",
"gulp-terser": "2.1.0"
Expand Down
8 changes: 6 additions & 2 deletions packages/crafty-preset-babel/src/gulp.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ module.exports = function createTask(crafty, bundle, StreamHandler) {
const {
toTempFile
} = require("@swissquote/crafty-preset-eslint/src/eslintConfigurator");
const eslint = require("gulp-eslint7");
stream.add(eslint(toTempFile(crafty.config.eslint))).add(eslint.format());
const eslint = require("gulp-eslint-new");
stream.add(eslint(
{
overrideConfigFile: toTempFile(crafty.config.eslint)
}
)).add(eslint.format());

// Fail the build if we have linting
// errors and we build directly
Expand Down
2 changes: 1 addition & 1 deletion packages/crafty-preset-eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@swissquote/rollup-plugin-eslint": "1.16.3",
"copy-anything": "2.0.3",
"debug": "^4.1.0",
"eslint": "7.32.0",
"eslint": "8.0.1",
"eslint-webpack-plugin": "3.0.1",
"merge-anything": "4.0.1",
"resolve-from": "5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/crafty-preset-eslint/src/commands/jsLint.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ if (process.argv[2] === "jsLint") {
process.argv.push("--config");
process.argv.push(tmpfile);

require("eslint/bin/eslint");
require(".bin/eslint");
63 changes: 2 additions & 61 deletions packages/crafty-preset-eslint/src/patchModuleResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,6 @@
const path = require("path");
const fs = require("fs");

function getESLintFolderFromModule() {
let currentModule = module;

while (
!/[\\/]eslint[\\/]lib[\\/]cli-engine[\\/]config-array-factory\.js/i.test(
currentModule.filename
)
) {
if (!currentModule.parent) {
// This was tested with ESLint 7.5.0; other versions may not work
throw new Error(
"Failed to patch ESLint because the calling module was not recognized"
);
}
currentModule = currentModule.parent;
}
return path.join(path.dirname(currentModule.filename), "../..");
}

function getESLintrcFolderFromModule() {
let currentModule = module;

Expand All @@ -51,31 +32,12 @@ function getESLintrcFolderFromModule() {
return path.join(path.dirname(currentModule.filename), "..");
}

function checkESLintVersion(eslintPath) {
// Detect the ESLint package version
const eslintPackageJson = fs
.readFileSync(path.join(eslintPath, "package.json"))
.toString();
const eslintPackageObject = JSON.parse(eslintPackageJson);
const eslintPackageVersion = eslintPackageObject.version;
const versionMatch = /^([0-9]+)\./.exec(eslintPackageVersion); // parse the SemVer MAJOR part
if (!versionMatch) {
throw new Error(`Unable to parse ESLint version: ${eslintPackageVersion}`);
}
const eslintMajorVersion = Number(versionMatch[1]);
if (eslintMajorVersion !== 7) {
throw new Error(
`The patch-eslint.js script has only been tested with ESLint version 7.x. (Your version: ${eslintPackageVersion})`
);
}
}

function patch(eslintPath) {
const moduleResolverPath = path.join(
eslintPath,
"lib/shared/relative-module-resolver"
"dist/eslintrc.cjs"
);
const ModuleResolver = require(moduleResolverPath);
const ModuleResolver = require(moduleResolverPath).Legacy.ModuleResolver;

const originalResolve = ModuleResolver.resolve;

Expand All @@ -98,27 +60,6 @@ function patch(eslintPath) {
let succeeded = false;
const errors = [];

// Patch ESLint directly
// This works if it's a version from before it was separated into @eslint/eslintrc
const eslintPossiblePaths = [
getESLintFolderFromModule,
() => require.resolve("eslint/package.json").replace(/\/package\.json$/, ""),
() => path.join(process.cwd(), "node_modules", "eslint")
];

eslintPossiblePaths.forEach(mainEslintFolderFn => {
try {
const mainEslintFolder = mainEslintFolderFn();
if (fs.existsSync(mainEslintFolder)) {
checkESLintVersion(mainEslintFolder);
patch(mainEslintFolder);
succeeded = true;
}
} catch (e) {
errors.push(e);
}
});

// Patch @eslint/eslintrc when it's found
const eslintrcPossiblePaths = [
getESLintrcFolderFromModule,
Expand Down
2 changes: 1 addition & 1 deletion packages/crafty-preset-swc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"debug": "^4.1.0",
"find-up": "5.0.0",
"gulp-concat": "2.6.1",
"gulp-eslint7": "0.3.2",
"gulp-eslint-new": "0.4.0",
"gulp-newer": "1.4.0",
"gulp-sourcemaps": "3.0.0",
"gulp-swc": "1.1.1",
Expand Down
8 changes: 6 additions & 2 deletions packages/crafty-preset-swc/src/gulp.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ module.exports = function createTask(crafty, bundle, StreamHandler) {
const {
toTempFile
} = require("@swissquote/crafty-preset-eslint/src/eslintConfigurator");
const eslint = require("gulp-eslint7");
stream.add(eslint(toTempFile(crafty.config.eslint))).add(eslint.format());
const eslint = require("gulp-eslint-new");
stream.add(eslint(
{
overrideConfigFile: toTempFile(crafty.config.eslint)
}
)).add(eslint.format());

// Fail the build if we have linting
// errors and we build directly
Expand Down
2 changes: 1 addition & 1 deletion packages/crafty-preset-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"find-up": "5.0.0",
"fork-ts-checker-webpack-plugin": "6.3.4",
"gulp-babel": "8.0.0",
"gulp-eslint7": "0.3.2",
"gulp-eslint-new": "0.4.0",
"gulp-sourcemaps": "3.0.0",
"gulp-typescript": "5.0.1",
"tmp": "0.2.1",
Expand Down
8 changes: 6 additions & 2 deletions packages/crafty-preset-typescript/src/gulp.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ module.exports = function createTask(crafty, bundle, StreamHandler) {
const {
toTempFile
} = require("@swissquote/crafty-preset-eslint/src/eslintConfigurator");
const eslint = require("gulp-eslint7");
const eslint = require("gulp-eslint-new");
stream
.add(eslint({ configFile: toTempFile(crafty.config.eslint) }))
.add(eslint(
{
overrideConfigFile: toTempFile(crafty.config.eslint)
}
))
.add(eslint.format());

// Fail the build if we have linting
Expand Down
5 changes: 4 additions & 1 deletion packages/eslint-plugin-swissquote/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ module.exports = {
],
testEnvironment: "node",
verbose: true,
coveragePathIgnorePatterns: ["node_modules", "coverage"]
coveragePathIgnorePatterns: ["node_modules", "coverage"],
moduleNameMapper: {
"eslint/use-at-your-own-risk": "eslint/lib/unsupported-api.js"
}
};
4 changes: 2 additions & 2 deletions packages/eslint-plugin-swissquote/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
"typescript": "4.4.4"
},
"peerDependency": {
"eslint": "^6.0.0 | ^7.0.0"
"eslint": "^6.0.0 | ^7.0.0 | ^8.0.0"
},
"devDependencies": {
"eslint": "7.32.0",
"eslint": "8.0.1",
"jest": "27.2.5"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/rollup-plugin-eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
},
"dependencies": {
"@rollup/pluginutils": "4.1.1",
"eslint": "7.32.0"
"eslint": "8.0.1"
}
}
Loading

0 comments on commit fdade2a

Please sign in to comment.