Skip to content

Commit

Permalink
WIP on updating to eslint 8
Browse files Browse the repository at this point in the history
  • Loading branch information
geek committed Oct 10, 2021
1 parent e7b0550 commit 0ea7ce4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
15 changes: 11 additions & 4 deletions lib/linter/index.js
Expand Up @@ -10,7 +10,7 @@ const Hoek = require('@hapi/hoek');
const internals = {};


exports.lint = function () {
exports.lint = async function () {

const configuration = {
ignore: true
Expand All @@ -32,8 +32,8 @@ exports.lint = function () {

let results;
try {
const engine = new Eslint.CLIEngine(configuration);
results = engine.executeOnFiles(['.']);
const eslint = new Eslint.ESLint(configuration);
results = await eslint.lintFiles(['.']);
}
catch (ex) {
results = {
Expand Down Expand Up @@ -67,4 +67,11 @@ exports.lint = function () {
});
};

process.send(exports.lint());
async function main () {

const results = await exports.lint();
process.send(results);
}

main();

12 changes: 6 additions & 6 deletions lib/modules/coverage.js
Expand Up @@ -18,7 +18,7 @@ const Transform = require('./transform');
const internals = {
ext: Symbol.for('@hapi/lab/coverage/initialize'),
_state: Symbol.for('@hapi/lab/coverage/_state'),
EslintEngine: new ESLint.CLIEngine({ baseConfig: Eslintrc })
eslint: new ESLint.ESLint({ baseConfig: Eslintrc })
};


Expand Down Expand Up @@ -116,13 +116,13 @@ internals.escape = function (string) {

internals.prime = function (extension) {

require.extensions[extension] = function (localModule, filename) {
require.extensions[extension] = async function (localModule, filename) {

// We never want to instrument eslint configs in order to avoid infinite recursion
if (Path.basename(filename, extension) !== '.eslintrc') {
for (let i = 0; i < internals.state.patterns.length; ++i) {
if (internals.state.patterns[i].test(filename.replace(/\\/g, '/'))) {
return localModule._compile(internals.instrument(filename), filename);
return localModule._compile(await internals.instrument(filename), filename);
}
}
}
Expand All @@ -133,7 +133,7 @@ internals.prime = function (extension) {
};


internals.instrument = function (filename) {
internals.instrument = async function (filename) {

filename = filename.replace(/\\/g, '/');

Expand Down Expand Up @@ -334,7 +334,7 @@ internals.instrument = function (filename) {

// Parse tree

const eslintConfig = internals.EslintEngine.getConfigForFile(filename);
const eslintConfig = await internals.eslint.calculateConfigForFile(filename);
const tree = ESLintParser.parse(content, {
...eslintConfig.parserOptions,
loc: true,
Expand Down Expand Up @@ -540,7 +540,7 @@ exports.analyze = async function (options) {
const filename = file.replace(/\\/g, '/');
if (pattern.test(filename)) {
if (!report[filename]) {
internals.instrument(filename);
await internals.instrument(filename);
}

report[filename].source = internals.state.sources[filename] || [];
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -19,13 +19,13 @@
]
},
"dependencies": {
"@babel/core": "^7.14.3",
"@babel/eslint-parser": "^7.14.3",
"@babel/core": "^7.15.8",
"@babel/eslint-parser": "^7.15.8",
"@hapi/bossy": "5.x.x",
"@hapi/eslint-plugin": "^5.1.0",
"@hapi/hoek": "9.x.x",
"diff": "4.x.x",
"eslint": "7.x.x",
"eslint": "8.x.x",
"find-rc": "4.x.x",
"globby": "10.x.x",
"handlebars": "4.x.x",
Expand Down
4 changes: 2 additions & 2 deletions test/reporters.js
Expand Up @@ -25,9 +25,9 @@ const it = lab.it;
const expect = Code.expect;


describe('Reporter', () => {
describe('Reporter', async () => {

Lab.coverage.instrument({ coveragePath: Path.join(__dirname, './coverage/'), coverageExclude: 'exclude' });
await Lab.coverage.instrument({ coveragePath: Path.join(__dirname, './coverage/'), coverageExclude: 'exclude' });

it('outputs to a stream', async () => {

Expand Down

0 comments on commit 0ea7ce4

Please sign in to comment.