Skip to content

Commit

Permalink
Update lint runner to support alternate parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesshore committed Feb 19, 2023
1 parent 3d96cef commit 580e739
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions build/util/lint_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
import eslint from "eslint";
import fs from "node:fs";
import { promisify } from "node:util";
import { Legacy } from "@eslint/eslintrc";
const { ConfigArrayFactory } = Legacy;

const linter = new (eslint).Linter();
const linter = new eslint.Linter();

export function validateSource(sourceCode, options, description) {
description = description ? description + " " : "";

const messages = linter.verify(sourceCode, options);
const configArrayFactory = new ConfigArrayFactory();
const configArray = configArrayFactory.create(options);

const messages = linter.verify(sourceCode, configArray);
const pass = (messages.length === 0);

if (pass) {
Expand All @@ -19,7 +24,7 @@ export function validateSource(sourceCode, options, description) {
console.log("\n" + description + "failed");
messages.forEach(function(error) {
const code = eslint.SourceCode.splitLines(sourceCode)[error.line - 1];
console.log(error.line + ": " + code.trim());
if (error.line !== 0) console.log(error.line + ": " + code?.trim());
console.log(" " + error.message);
});
}
Expand Down

0 comments on commit 580e739

Please sign in to comment.