Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to eslint 8 #8580

Merged
merged 3 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@types/node": ">= 18",
"buffer": "mischnic/buffer#b8a4fa94",
"cross-env": "^7.0.0",
"eslint": "^7.20.0",
"eslint": "^8.41.0",
"flow-bin": "0.184.0",
"glob": "^7.1.6",
"gulp": "^4.0.2",
Expand Down
2 changes: 0 additions & 2 deletions packages/dev/eslint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ module.exports = {
'plugin:monorepo/recommended',
'plugin:react/recommended',
'prettier',
'prettier/flowtype',
'prettier/react',
],
parser: '@babel/eslint-parser',
plugins: ['@parcel', 'flowtype', 'import', 'monorepo', 'react', 'mocha'],
Expand Down
8 changes: 5 additions & 3 deletions packages/dev/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
"version": "2.11.0",
"dependencies": {
"@babel/eslint-parser": "^7.22.11",
"@babel/plugin-syntax-flow": "^7.14.5",
"@babel/plugin-transform-react-jsx": "^7.14.9",
"@parcel/eslint-plugin": "2.11.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-flowtype": "^5.2.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-flowtype": "^8.0.3",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-mocha": "^8.0.0",
"eslint-plugin-monorepo": "^0.3.2",
"eslint-plugin-react": "^7.22.0"
"eslint-plugin-react": "^7.32.2"
},
"peerDependencies": {
"@babel/core": "^7.22.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"devDependencies": {
"@babel/core": "^7.22.11",
"@babel/eslint-parser": "^7.22.11",
"eslint": "^7.20.0"
"eslint": "^8.41.0"
}
}
6 changes: 3 additions & 3 deletions packages/utils/parcel-lsp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
},
"devDependencies": {
"@types/node": ">= 18",
"@typescript-eslint/eslint-plugin": "^4.14.1",
"@typescript-eslint/parser": "^4.14.1",
"eslint": "^7.19.0",
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
"eslint": "^8.41.0",
"typescript": ">=3.0.0"
},
"targets": {
Expand Down
6 changes: 3 additions & 3 deletions packages/utils/parcelforvscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@
"@types/mocha": "^8.0.4",
"@types/node": ">= 18",
"@types/vscode": "^1.67.0",
"@typescript-eslint/eslint-plugin": "^4.14.1",
"@typescript-eslint/parser": "^4.14.1",
"eslint": "^7.19.0",
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
"eslint": "^8.41.0",
"glob": "^7.1.6",
"mocha": "^8.2.1",
"typescript": ">=3.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/validators/eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"chalk": "^4.1.0"
},
"devDependencies": {
"eslint": "^6.0.0 || ^7.0.0"
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
},
"peerDependencies": {
"eslint": "^6.0.0 || ^7.0.0"
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
}
}
89 changes: 50 additions & 39 deletions packages/validators/eslint/src/EslintValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,72 @@ import {type DiagnosticCodeFrame, escapeMarkdown} from '@parcel/diagnostic';
import eslint from 'eslint';
import invariant from 'assert';

// For eslint <8.0.0
let cliEngine = null;
// For eslint >=8.0.0
let eslintEngine = null;

export default (new Validator({
async validate({asset}) {
if (!cliEngine) {
cliEngine = new eslint.CLIEngine({});
if (!cliEngine && !eslintEngine) {
if (eslint.ESLint) {
eslintEngine = new eslint.ESLint({});
} else {
cliEngine = new eslint.CLIEngine({});
}
}
let code = await asset.getCode();

invariant(cliEngine != null);
let report = cliEngine.executeOnText(code, asset.filePath);
let results;
if (cliEngine != null) {
results = cliEngine.executeOnText(code, asset.filePath).results;
} else if (eslintEngine != null) {
results = await eslintEngine.lintText(code, {filePath: asset.filePath});
} else {
invariant(false);
}

let validatorResult = {
warnings: [],
errors: [],
};

if (report.results.length > 0) {
for (let result of report.results) {
if (!result.errorCount && !result.warningCount) continue;
for (let result of results) {
if (!result.errorCount && !result.warningCount) continue;

let codeframe: DiagnosticCodeFrame = {
filePath: asset.filePath,
code: result.source,
codeHighlights: result.messages.map(message => {
let start = {
line: message.line,
column: message.column,
};
return {
start,
// Parse errors have no ending
end:
message.endLine != null
? {
line: message.endLine,
column: message.endColumn,
}
: start,
message: escapeMarkdown(message.message),
};
}),
};
let codeframe: DiagnosticCodeFrame = {
filePath: asset.filePath,
code: result.source,
codeHighlights: result.messages.map(message => {
let start = {
line: message.line,
column: message.column,
};
return {
start,
// Parse errors have no ending
end:
message.endLine != null
? {
line: message.endLine,
column: message.endColumn - 1,
}
: start,
message: escapeMarkdown(message.message),
};
}),
};

let diagnostic = {
origin: '@parcel/validator-eslint',
message: `ESLint found **${result.errorCount}** __errors__ and **${result.warningCount}** __warnings__.`,
codeFrames: [codeframe],
};
let diagnostic = {
origin: '@parcel/validator-eslint',
message: `ESLint found **${result.errorCount}** __errors__ and **${result.warningCount}** __warnings__.`,
codeFrames: [codeframe],
};

if (result.errorCount > 0) {
validatorResult.errors.push(diagnostic);
} else {
validatorResult.warnings.push(diagnostic);
}
if (result.errorCount > 0) {
validatorResult.errors.push(diagnostic);
} else {
validatorResult.warnings.push(diagnostic);
}
}

Expand Down
Loading
Loading