Skip to content

Commit

Permalink
Merge pull request #388 from Turbo87/eslint-options
Browse files Browse the repository at this point in the history
Adjust test suite to be compatible with ESLint 9
  • Loading branch information
Turbo87 authored Jun 13, 2024
2 parents 22a2c0a + eaf4b7c commit 9957878
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "eslint:recommended",
"parserOptions": { "ecmaVersion": 6 },
"parserOptions": { "ecmaVersion": 2018 },
"env": {
"mocha": true,
"node": true
Expand Down
5 changes: 3 additions & 2 deletions tests/lib/rules/missing-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const rule = require('../../../lib/rules/missing-assertion');
const {RuleTester} = require('eslint');
const {ecmaVersion} = require('./utils');

let ruleTester = new RuleTester();
ruleTester.run('missing-assertion', rule, {
Expand Down Expand Up @@ -31,7 +32,7 @@ ruleTester.run('missing-assertion', rule, {
`
}, {
code: 'it("works as expected", () => expect(true).to.be.true);',
parserOptions: { ecmaVersion: 6 },
...ecmaVersion(6),
} ],

invalid: [{
Expand All @@ -54,7 +55,7 @@ ruleTester.run('missing-assertion', rule, {
}]
}, {
code: 'it("fails as expected", () => expect(true));',
parserOptions: { ecmaVersion: 6 },
...ecmaVersion(6),
errors: [{
message: 'expect(...) used without assertion'
}]
Expand Down
13 changes: 4 additions & 9 deletions tests/lib/rules/no-inner-literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const rule = require('../../../lib/rules/no-inner-literal');
const {RuleTester} = require('eslint');
const {ecmaVersion} = require('./utils');

let ruleTester = new RuleTester();
ruleTester.run('no-inner-literal', rule, {
Expand All @@ -19,14 +20,10 @@ ruleTester.run('no-inner-literal', rule, {
code: 'expect(a).to.equal(5);'
}, {
code: 'expect(`template literal`).to.equal(5);',
parserOptions: {
ecmaVersion: 2015
}
...ecmaVersion(2015),
}, {
code: 'expect(tagged`template literal`).to.equal(5);',
parserOptions: {
ecmaVersion: 2015
}
...ecmaVersion(2015),
}, {
code: `
it('should have no problems', function () {
Expand Down Expand Up @@ -130,8 +127,6 @@ ruleTester.run('no-inner-literal', rule, {
errors: [{
message: '`132n` used in expect()'
}],
parserOptions: {
ecmaVersion: 2020
}
...ecmaVersion(2020),
}]]
});
23 changes: 23 additions & 0 deletions tests/lib/rules/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const eslintPkg = require('eslint/package.json');

const USE_LANGUAGE_OPTIONS = eslintPkg.version.startsWith('9.');

function ecmaVersion(version) {
if (USE_LANGUAGE_OPTIONS) {
return {
languageOptions: {
ecmaVersion: version
}
};
}

return {
parserOptions: {
ecmaVersion: version
}
}
}

module.exports = {
ecmaVersion
};

0 comments on commit 9957878

Please sign in to comment.