Skip to content

Commit

Permalink
Upgrade to ESLint v8 (#814)
Browse files Browse the repository at this point in the history
Co-authored-by: Remus Mate <rmate@seek.com.au>
  • Loading branch information
askoufis and mrm007 committed May 25, 2023
1 parent f7c4211 commit 0521cbf
Show file tree
Hide file tree
Showing 5 changed files with 240 additions and 274 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-laws-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sku': minor
---

Upgrade ESLint to v8
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"@types/jest": "^29.0.0",
"debug": "^4.3.1",
"dedent": "^0.7.0",
"eslint": "^7.18.0",
"eslint-config-seek": "^11.0.0",
"eslint": "^8.41.0",
"eslint-config-seek": "^11.1.2",
"eslint-plugin-jsdoc": "^44.2.4",
"gh-pages": "^3.1.0",
"husky": "^8.0.3",
Expand Down
83 changes: 40 additions & 43 deletions packages/sku/lib/runESLint.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { yellow, cyan, gray } = require('chalk');
const EslintCLI = require('eslint').CLIEngine;
const { ESLint } = require('eslint');
const eslintConfig = require('../config/eslint/eslintConfig');
const {
js: jsExtensions,
Expand All @@ -11,56 +11,53 @@ const extensions = [...tsExtensions, ...jsExtensions].map((ext) => `.${ext}`);
/**
* @param {{ fix?: boolean, paths?: string[] }}
*/
const runESLint = ({ fix = false, paths }) =>
new Promise((resolve, reject) => {
console.log(cyan(`${fix ? 'Fixing' : 'Checking'} code with ESLint`));
const runESLint = async ({ fix = false, paths }) => {
console.log(cyan(`${fix ? 'Fixing' : 'Checking'} code with ESLint`));

const cli = new EslintCLI({
baseConfig: eslintConfig,
extensions,
useEslintrc: false,
fix,
});
const checkAll = typeof paths === 'undefined';
/* Whitelist the file extensions that our ESLint setup currently supports */
const filteredFilePaths = checkAll
? ['.']
: paths.filter((filePath) =>
[...extensions, '.json'].some((ext) => filePath.endsWith(ext)),
);

if (filteredFilePaths.length === 0) {
console.log(gray(`No JS files to lint`));
} else {
console.log(gray(`Paths: ${filteredFilePaths.join(' ')}`));
try {
const report = cli.executeOnFiles(filteredFilePaths);
const eslint = new ESLint({
baseConfig: eslintConfig,
extensions,
useEslintrc: false,
fix,
});
const checkAll = typeof paths === 'undefined';
/* Whitelist the file extensions that our ESLint setup currently supports */
const filteredFilePaths = checkAll
? ['.']
: paths.filter((filePath) =>
[...extensions, '.json'].some((ext) => filePath.endsWith(ext)),
);

if (fix) {
EslintCLI.outputFixes(report);
} else {
const { errorCount, warningCount, results } = report;
if (filteredFilePaths.length === 0) {
console.log(gray(`No JS files to lint`));
} else {
console.log(gray(`Paths: ${filteredFilePaths.join(' ')}`));
try {
const report = await eslint.lintFiles(filteredFilePaths);

if (errorCount || warningCount) {
const formatter = cli.getFormatter();
console.log(formatter(results));
}
if (fix) {
ESLint.outputFixes(report);
} else {
const { errorCount, warningCount, results } = report;

if (errorCount > 0) {
reject();
}
if (errorCount || warningCount) {
const formatter = await eslint.loadFormatter();
console.log(formatter(results));
}
} catch (e) {
if (e && e.message && e.message.includes('No files matching')) {
console.warn(yellow(`Warning: ${e.message}`));
} else {
reject(e);

if (errorCount > 0) {
return Promise.reject();
}
}
} catch (e) {
if (e && e.message && e.message.includes('No files matching')) {
console.warn(yellow(`Warning: ${e.message}`));
} else {
return Promise.reject();
}
}

resolve();
});
}
};

module.exports = {
check: (paths) => runESLint({ paths }),
Expand Down
4 changes: 2 additions & 2 deletions packages/sku/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
"esbuild": "^0.17.0",
"esbuild-register": "^3.3.3",
"escape-string-regexp": "^4.0.0",
"eslint": "^7.18.0",
"eslint-config-seek": "^11.1.0",
"eslint": "^8.41.0",
"eslint-config-seek": "^11.1.2",
"exception-formatter": "^2.1.2",
"express": "^4.16.3",
"fast-glob": "^3.2.5",
Expand Down
Loading

0 comments on commit 0521cbf

Please sign in to comment.