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

ci: eslint v9 test #64

Merged
merged 10 commits into from
Apr 19, 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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
website/
tools/
eslint.config.mjs
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ module.exports = {
extends: ['eslint:recommended', 'plugin:node/recommended', 'plugin:eslint-plugin/recommended'],
env: {
es6: true
},
rules: {
"node/no-extraneous-require": "off"
}
}
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ jobs:
- run: npm run lint
- run: npm run test

eslint9_test:
name: Test eslint-plugin-wxml with eslint9
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with: {node-version: '${{ env.NODE_VERSION }}'}
- run: npm install
- run: npm install eslint@9
- run: npm install semver
- run: npm run lint
- run: npm run test

eslint8_test:
name: Test eslint-plugin-wxml with eslint8
runs-on: ubuntu-latest
Expand All @@ -45,6 +59,7 @@ jobs:
with: {node-version: '${{ env.NODE_VERSION }}'}
- run: npm install
- run: npm install eslint@8
- run: npm install semver
- run: npm run lint
- run: npm run test

Expand Down
17 changes: 17 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import js from "@eslint/js";

export default [
{
...js.configs.recommended,
files: ["lib/**/*.js"],
ignores: ["website/**", "tools/**"]
},
{
languageOptions: {
globals: {
module: "readonly",
require: "readonly",
}
}
}
];
4 changes: 4 additions & 0 deletions lib/rules/no-unexpected-string-bool.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ module.exports = {
if (node.value === "true" || node.value === "false") {
context.report({
node,
data: {
true: "{{true}}",
false: "{{false}}",
},
messageId: node.value === "true" ? "trueString" : "falseString",
});
}
Expand Down
6 changes: 5 additions & 1 deletion lib/rules/omit-bool-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ module.exports = {
context.report({
node,
messageId: "omitWarn",
data: { attrKey: node.key },
data: {
attrKey: node.key,
true: "{{true}}",
false: "{{false}}",
},
});
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/report-interpolation-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ module.exports = {
return;
}
try {
// eslint-disable-next-line node/no-extraneous-require
espreeParser = require("espree");
// eslint-disable-next-line no-unused-vars
} catch (_) {
// ...
}
Expand All @@ -38,11 +38,13 @@ module.exports = {
espreeParser.parse(`({${node.value}})`, {
ecmaVersion: espreeParser.latestEcmaVersion,
});
// eslint-disable-next-line no-unused-vars
} catch (_) {
try {
espreeParser.parse(`(${node.value})`, {
ecmaVersion: espreeParser.latestEcmaVersion,
});
// eslint-disable-next-line no-unused-vars
} catch (_) {
context.report({
node,
Expand Down
12 changes: 12 additions & 0 deletions tests/rule-tester-compat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const eslint = require("eslint");
const semver = require("semver");

const ruleTester = semver.gte(eslint.Linter.version, "9.0.0-0")
? new eslint.RuleTester({
languageOptions: {
parser: require("@wxml/parser"),
},
})
: new eslint.RuleTester({ parser: require.resolve("@wxml/parser") });

module.exports.RuleTester = ruleTester;
6 changes: 1 addition & 5 deletions tests/rules/colon-style-event-binding.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/colon-style-event-binding");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("colon-style-event-binding", rule, {
valid: [
{
Expand Down
6 changes: 1 addition & 5 deletions tests/rules/empty-tag-self-closing.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/empty-tag-self-closing");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("empty-tag-self-closing", rule, {
valid: [
{
Expand Down
6 changes: 1 addition & 5 deletions tests/rules/event-binding-style.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/event-binding-style");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("event-binding-style", rule, {
valid: [
{
Expand Down
6 changes: 1 addition & 5 deletions tests/rules/forbid-attributes.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/forbid-attributes");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("forbid-attributes", rule, {
valid: [
{
Expand Down
6 changes: 1 addition & 5 deletions tests/rules/forbid-tags.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/forbid-tags");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("forbid-tags", rule, {
valid: [
{
Expand Down
6 changes: 1 addition & 5 deletions tests/rules/max-depth.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/max-depth");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("max-depth", rule, {
valid: [
{
Expand Down
6 changes: 1 addition & 5 deletions tests/rules/max-len.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/max-len");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("max-len", rule, {
valid: [
{
Expand Down
6 changes: 1 addition & 5 deletions tests/rules/max-lines.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
const fs = require("fs");
const path = require("path");
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/max-lines");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

function readFixureFiles(filename) {
if (filename) {
return fs.readFileSync(
Expand Down
6 changes: 1 addition & 5 deletions tests/rules/no-const-and-let-in-wxs.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/no-const-and-let-in-wxs");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("no-const-and-let-in-wxs", rule, {
valid: [
{
Expand Down
6 changes: 1 addition & 5 deletions tests/rules/no-dot-this-in-wx-key.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/no-dot-this-in-wx-key");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("no-dot-this-in-wx-key", rule, {
valid: [
{
Expand Down
6 changes: 1 addition & 5 deletions tests/rules/no-duplicate-attributes.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/no-duplicate-attributes");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("no-duplicate-attributes", rule, {
valid: [
{
Expand Down
6 changes: 1 addition & 5 deletions tests/rules/no-dynamic-wx-key.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/no-dynamic-wx-key");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("no-dynamic-wx-key", rule, {
valid: [
{
Expand Down
6 changes: 1 addition & 5 deletions tests/rules/no-inconsistent-tagname.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/no-inconsistent-tagname");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("no-inconsistent-tagname", rule, {
valid: [
{
Expand Down
6 changes: 1 addition & 5 deletions tests/rules/no-index-in-wx-key.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/no-index-in-wx-key");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("no-index-in-wx-key", rule, {
valid: [
{
Expand Down
6 changes: 1 addition & 5 deletions tests/rules/no-inline-wxs.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/no-inline-wxs");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("no-inline-wxs", rule, {
valid: [
{
Expand Down
36 changes: 28 additions & 8 deletions tests/rules/no-unexpected-string-bool.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/no-unexpected-string-bool");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("no-unexpected-string-bool", rule, {
valid: [
{
Expand All @@ -24,17 +20,41 @@ tester.run("no-unexpected-string-bool", rule, {
{
filename: "test.wxml",
code: `<popup wx:if="true" />`,
errors: [{ messageId: "trueString" }],
errors: [
{
messageId: "trueString",
data: {
true: "{{true}}",
false: "{{false}}",
},
},
],
},
{
filename: "test.wxml",
code: `<popup wx:if="false" />`,
errors: [{ messageId: "falseString" }],
errors: [
{
messageId: "falseString",
data: {
true: "{{true}}",
false: "{{false}}",
},
},
],
},
{
filename: "test.wxml",
code: `<dialog showAnime="false" />`,
errors: [{ messageId: "falseString" }],
errors: [
{
messageId: "falseString",
data: {
true: "{{true}}",
false: "{{false}}",
},
},
],
},
],
});
6 changes: 1 addition & 5 deletions tests/rules/no-unnecessary-block.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/no-unnecessary-block");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("no-unnecessary-block", rule, {
valid: [
{
Expand Down
6 changes: 1 addition & 5 deletions tests/rules/no-vue-directive.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/no-vue-directive");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("no-vue-directive", rule, {
valid: [
{
Expand Down
6 changes: 1 addition & 5 deletions tests/rules/no-wx-for-with-wx-else.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const RuleTester = require("eslint").RuleTester;
const tester = require("../rule-tester-compat").RuleTester;
const rule = require("../../lib/rules/no-wx-for-with-wx-else");

const tester = new RuleTester({
parser: require.resolve("@wxml/parser"),
});

tester.run("no-wx-for-with-wx-else", rule, {
valid: [
{
Expand Down
Loading
Loading