diff --git a/.eslintrc.js b/.eslintrc.js index 805090a4..2b419350 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,9 +1,9 @@ "use strict"; -var fs = require("fs"); -var path = require("path"); -var PACKAGE_NAME = require("./package").name; -var SYMLINK_LOCATION = path.join(__dirname, "node_modules", PACKAGE_NAME); +const fs = require("fs"); +const path = require("path"); +const PACKAGE_NAME = require("./package").name; +const SYMLINK_LOCATION = path.join(__dirname, "node_modules", PACKAGE_NAME); // Symlink node_modules/eslint-plugin-markdown to this directory so that ESLint // resolves this plugin name correctly. @@ -12,37 +12,37 @@ if (!fs.existsSync(SYMLINK_LOCATION)) { } module.exports = { - "root": true, + root: true, - "parserOptions": { - "ecmaVersion": 2018 + parserOptions: { + ecmaVersion: 2018 }, - "plugins": [ + plugins: [ PACKAGE_NAME ], - "env": { - "node": true + env: { + node: true }, - "extends": "eslint", + extends: "eslint", - "ignorePatterns": ["examples"], + ignorePatterns: ["examples"], - "overrides": [ + overrides: [ { - "files": ["**/*.md"], - "processor": "markdown/markdown" + files: ["**/*.md"], + processor: "markdown/markdown" }, { - "files": ["**/*.md/*.js"], - "parserOptions": { - "ecmaFeatures": { - "impliedStrict": true + files: ["**/*.md/*.js"], + parserOptions: { + ecmaFeatures: { + impliedStrict: true } }, - "rules": { + rules: { "lines-around-comment": "off" } } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d4ad541d..21c12ebc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Install Node.js uses: actions/setup-node@v2 - name: Install Packages @@ -27,23 +27,39 @@ jobs: strategy: matrix: os: [ubuntu-latest] - node-version: ["8.10.0", 8.x, 10.x, 12.x, 13.x, 14.x] + eslint: [6, 7, 8] + node: [8.10, 8, 10, 12, 14, 16] + exclude: + - eslint: 8 + node: 10 + - eslint: 8 + node: 8 + - eslint: 8 + node: 8.10 + - eslint: 7 + node: 8 + - eslint: 7 + node: 8.10 include: - - os: windows-latest - node: "12.x" - - os: macOS-latest - node: "12.x" + - os: windows-latest + eslint: 8 + node: 16 + - os: macOS-latest + eslint: 8 + node: 16 runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@v1 - - name: Install Node.js ${{ matrix.node-version }} + uses: actions/checkout@v2 + - name: Install Node.js ${{ matrix.node }} uses: actions/setup-node@v2 with: - node-version: ${{ matrix.node-version }} + node-version: ${{ matrix.node }} - name: Install Packages run: npm install env: CI: true + - name: Install ESLint@${{ matrix.eslint }} + run: npm install eslint@${{ matrix.eslint }} - name: Test run: npm run test-cov diff --git a/package.json b/package.json index d1a50208..14c0cfef 100644 --- a/package.json +++ b/package.json @@ -38,10 +38,10 @@ ], "devDependencies": { "chai": "^4.2.0", - "eslint": "^6.8.0", - "eslint-config-eslint": "^6.0.0", - "eslint-plugin-jsdoc": "^15.9.5", - "eslint-plugin-node": "^9.0.0", + "eslint": "^8.0.0", + "eslint-config-eslint": "^7.0.0", + "eslint-plugin-jsdoc": "^36.1.1", + "eslint-plugin-node": "^11.1.0", "eslint-release": "^3.1.2", "mocha": "^6.2.2", "nyc": "^14.1.1" @@ -50,9 +50,9 @@ "mdast-util-from-markdown": "^0.8.5" }, "peerDependencies": { - "eslint": ">=6.0.0" + "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" }, "engines": { - "node": "^8.10.0 || ^10.12.0 || >= 12.0.0" + "node": "^8.10.0 || ^10.12.0 || >=12.0.0" } } diff --git a/tests/lib/plugin.js b/tests/lib/plugin.js index c889d797..20b365eb 100644 --- a/tests/lib/plugin.js +++ b/tests/lib/plugin.js @@ -7,7 +7,7 @@ const assert = require("chai").assert; const execSync = require("child_process").execSync; -const CLIEngine = require("eslint").CLIEngine; +const { CLIEngine, ESLint } = require("eslint"); const path = require("path"); const plugin = require("../.."); @@ -19,19 +19,27 @@ const plugin = require("../.."); * Helper function which creates CLIEngine instance with enabled/disabled autofix feature. * @param {string} fixtureConfigName ESLint JSON config fixture filename. * @param {CLIEngineOptions} [options={}] Whether to enable autofix feature. - * @returns {CLIEngine} CLIEngine instance to execute in tests. + * @returns {ESLint} ESLint instance to execute in tests. */ function initCLI(fixtureConfigName, options = {}) { - const cli = new CLIEngine({ + if (ESLint) { // ESLint v7+ + return new ESLint({ + cwd: path.resolve(__dirname, "../fixtures/"), + ignore: false, + useEslintrc: false, + overrideConfigFile: path.resolve(__dirname, "../fixtures/", fixtureConfigName), + plugins: { markdown: plugin }, + ...options + }); + } + + return new CLIEngine({ cwd: path.resolve(__dirname, "../fixtures/"), ignore: false, useEslintrc: false, configFile: path.resolve(__dirname, "../fixtures/", fixtureConfigName), ...options - }); - - cli.addPlugin("markdown", plugin); - return cli; + }).addPlugin("markdown", plugin); } describe("recommended config", () => { @@ -72,13 +80,17 @@ describe("recommended config", () => { }); it("should include the plugin", () => { - const config = cli.getConfigForFile("test.md"); + const config = ESLint + ? cli.calculateConfigForFile("test.md") + : cli.getConfigForFile("test.md"); assert.include(config.plugins, "markdown"); }); it("applies convenience configuration", () => { - const config = cli.getConfigForFile("subdir/test.md/0.js"); + const config = ESLint + ? cli.calculateConfigForFile("subdir/test.md/0.js") + : cli.getConfigForFile("subdir/test.md/0.js"); assert.deepStrictEqual(config.parserOptions, { ecmaFeatures: { @@ -95,7 +107,9 @@ describe("recommended config", () => { }); it("overrides configure processor to parse .md file code blocks", () => { - const report = cli.executeOnText(shortText, "test.md"); + const report = ESLint + ? cli.lintText(shortText, { filePath: "test.md" }) + : cli.executeOnText(shortText, "test.md"); assert.strictEqual(report.results.length, 1); assert.strictEqual(report.results[0].messages.length, 1); @@ -118,7 +132,9 @@ describe("plugin", () => { }); it("should run on .md files", () => { - const report = cli.executeOnText(shortText, "test.md"); + const report = ESLint + ? cli.lintText(shortText, { filePath: "test.md" }) + : cli.executeOnText(shortText, "test.md"); assert.strictEqual(report.results.length, 1); assert.strictEqual(report.results[0].messages.length, 1); @@ -138,7 +154,9 @@ describe("plugin", () => { "var foo = blah", "```" ].join("\n"); - const report = cli.executeOnText(code, "test.md"); + const report = ESLint + ? cli.lintText(code, { filePath: "test.md" }) + : cli.executeOnText(code, "test.md"); assert.strictEqual(report.results[0].messages[0].message, "'baz' is not defined."); assert.strictEqual(report.results[0].messages[0].line, 5); @@ -158,7 +176,9 @@ describe("plugin", () => { "console.log('a')", "```" ].join("\n"); - const report = cli.executeOnText(code, "test.md"); + const report = ESLint + ? cli.lintText(code, { filePath: "test.md" }) + : cli.executeOnText(code, "test.md"); assert.strictEqual(report.results[0].messages[0].line, 5); }); @@ -169,7 +189,9 @@ describe("plugin", () => { "!@#$%^&*()", "```" ].join("\n"); - const report = cli.executeOnText(code, "test.md"); + const report = ESLint + ? cli.lintText(code, { filePath: "test.md" }) + : cli.executeOnText(code, "test.md"); assert.strictEqual(report.results.length, 1); assert.strictEqual(report.results[0].messages.length, 1); @@ -192,7 +214,9 @@ describe("plugin", () => { "var foo = blah", "```" ].join("\n"); - const report = cli.executeOnText(code, "test.md"); + const report = ESLint + ? cli.lintText(code, { filePath: "test.md" }) + : cli.executeOnText(code, "test.md"); assert.strictEqual(report.results[0].messages[0].message, "'baz' is not defined."); assert.strictEqual(report.results[0].messages[0].line, 7); @@ -203,7 +227,9 @@ describe("plugin", () => { }); it("should run on .mkdn files", () => { - const report = cli.executeOnText(shortText, "test.mkdn"); + const report = ESLint + ? cli.lintText(shortText, { filePath: "test.mkdnd" }) + : cli.executeOnText(shortText, "test.mkdn"); assert.strictEqual(report.results.length, 1); assert.strictEqual(report.results[0].messages.length, 1); @@ -212,7 +238,9 @@ describe("plugin", () => { }); it("should run on .mdown files", () => { - const report = cli.executeOnText(shortText, "test.mdown"); + const report = ESLint + ? cli.lintText(shortText, { filePath: "test.mdown" }) + : cli.executeOnText(shortText, "test.mdown"); assert.strictEqual(report.results.length, 1); assert.strictEqual(report.results[0].messages.length, 1); @@ -221,7 +249,9 @@ describe("plugin", () => { }); it("should run on .markdown files", () => { - const report = cli.executeOnText(shortText, "test.markdown"); + const report = ESLint + ? cli.lintText(shortText, { filePath: "test.markdown" }) + : cli.executeOnText(shortText, "test.markdown"); assert.strictEqual(report.results.length, 1); assert.strictEqual(report.results[0].messages.length, 1); @@ -230,7 +260,9 @@ describe("plugin", () => { }); it("should run on files with any custom extension", () => { - const report = cli.executeOnText(shortText, "test.custom"); + const report = ESLint + ? cli.lintText(shortText, { filePath: "test.custom" }) + : cli.executeOnText(shortText, "test.custom"); assert.strictEqual(report.results.length, 1); assert.strictEqual(report.results[0].messages.length, 1); @@ -239,7 +271,9 @@ describe("plugin", () => { }); it("should extract blocks and remap messages", () => { - const report = cli.executeOnFiles([path.resolve(__dirname, "../fixtures/long.md")]); + const report = ESLint + ? cli.lintFiles([path.resolve(__dirname, "../fixtures/long.md")]) + : cli.executeOnFiles([path.resolve(__dirname, "../fixtures/long.md")]); assert.strictEqual(report.results.length, 1); assert.strictEqual(report.results[0].messages.length, 5); @@ -289,7 +323,9 @@ describe("plugin", () => { const recursiveCli = initCLI("eslintrc.json", { extensions: [".js", ".markdown", ".md"] }); - const report = recursiveCli.executeOnText(code, "test.md"); + const report = ESLint + ? recursiveCli.lintText(code, { filePath: "test.md" }) + : recursiveCli.executeOnText(code, "test.md"); assert.strictEqual(report.results.length, 1); assert.strictEqual(report.results[0].messages.length, 2); @@ -320,7 +356,9 @@ describe("plugin", () => { "console.log(double);", "```" ].join("\n"); - const report = cli.executeOnText(code, "test.md"); + const report = ESLint + ? cli.lintText(code, { filePath: "test.md" }) + : cli.executeOnText(code, "test.md"); assert.strictEqual(report.results.length, 1); assert.strictEqual(report.results[0].messages.length, 4); @@ -344,7 +382,9 @@ describe("plugin", () => { "\"use strict\";", "```" ].join("\n"); - const report = cli.executeOnText(code, "test.md"); + const report = ESLint + ? cli.lintText(code, { filePath: "test.md" }) + : cli.executeOnText(code, "test.md"); assert.strictEqual(report.results.length, 1); assert.strictEqual(report.results[0].messages.length, 1); @@ -374,7 +414,9 @@ describe("plugin", () => { "console.log(\"Hello, world!\")", "```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -397,7 +439,9 @@ describe("plugin", () => { "console.log(\"Hello, world!\")", "```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -426,7 +470,9 @@ describe("plugin", () => { "console.log(\"Hello, world!\")", "```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -451,7 +497,9 @@ describe("plugin", () => { "}", "```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -476,7 +524,9 @@ describe("plugin", () => { "}", "```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -497,7 +547,9 @@ describe("plugin", () => { "\"use strict\"", "```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -518,7 +570,9 @@ describe("plugin", () => { "console.log(\"Hello, world!\")", "````" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -539,7 +593,9 @@ describe("plugin", () => { "console.log(\"Hello, world!\");", "```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -560,7 +616,9 @@ describe("plugin", () => { " console.log(\"Hello, world!\")", " ```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -591,7 +649,9 @@ describe("plugin", () => { " }", " ```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -618,7 +678,9 @@ describe("plugin", () => { "world!\")", "```" ].join("\r\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -643,7 +705,9 @@ describe("plugin", () => { " console.log(\"Hello, world!\")", " ```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -666,7 +730,9 @@ describe("plugin", () => { " console.log(\"Hello, world!\")", " ```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -689,7 +755,9 @@ describe("plugin", () => { " console.log(\"Hello, world!\")", " ```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -712,7 +780,9 @@ describe("plugin", () => { " console.log(\"Hello, world!\")", " ```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -737,7 +807,9 @@ describe("plugin", () => { " console.log(\"Hello, world!\")", " ```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -764,7 +836,9 @@ describe("plugin", () => { " world!\")", " ```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -792,7 +866,9 @@ describe("plugin", () => { " console.log(\"Hello, world!\")", " ```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -819,7 +895,9 @@ describe("plugin", () => { "> world!\")", "> ```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -857,7 +935,9 @@ describe("plugin", () => { "> > world!\")", "> > ```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -886,7 +966,9 @@ describe("plugin", () => { " console.log(\"Hello, world!\");", " ```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -917,7 +999,9 @@ describe("plugin", () => { " console.log(\"Hello, world!\");", " ```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -941,7 +1025,9 @@ describe("plugin", () => { " console.log(\"Hello, world!\")", " ```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -964,7 +1050,9 @@ describe("plugin", () => { " console.log(\"Hello, world!\")", " ```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected); @@ -1007,7 +1095,9 @@ describe("plugin", () => { "};", "```" ].join("\n"); - const report = cli.executeOnText(input, "test.md"); + const report = ESLint + ? cli.lintText(input, { filePath: "test.md" }) + : cli.executeOnText(input, "test.md"); const actual = report.results[0].output; assert.strictEqual(actual, expected);