diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 86ccc5a..86477a9 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -16,8 +16,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2
- - uses: actions/setup-node@v2
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
with: {node-version: '${{ env.NODE_VERSION }}'}
- run: npm install
- run: npm run lint
@@ -28,13 +28,26 @@ jobs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2
- - uses: actions/setup-node@v2
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
with: {node-version: '${{ env.NODE_VERSION }}'}
- run: npm install
- run: npm run lint
- run: npm run test
+ eslint8_test:
+ name: Test eslint-plugin-wxml with eslint8
+ 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@8
+ - run: npm run lint
+ - run: npm run test
+
node_tests:
name: 'Test eslint-plugin-wxml on ${{matrix.os}} with node${{matrix.node}}'
strategy:
@@ -44,9 +57,9 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
# Pull repo to test machine
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v3
# Configures the node version used on GitHub-hosted runners
- - uses: actions/setup-node@v2
+ - uses: actions/setup-node@v3
with:
# The Node.js version to configure
node-version: ${{ matrix.node }}
@@ -55,7 +68,7 @@ jobs:
id: npm-cache-dir
run: |
echo "::set-output name=dir::$(npm config get cache)"
- - uses: actions/cache@v2
+ - uses: actions/cache@v3
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 14a8663..b1c25e1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+
+### Changed
+- Bump `@wxml/parser` version from `v0.4.0`
+### Added
+- Add ESLint 8 test suits
+- Add rule `report-interpolation-error`
+
## [0.6.3] - 2022-02-09
### Added
- Add rule `required-root-tag`
diff --git a/lib/index.js b/lib/index.js
index 9d875db..24500fc 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -21,6 +21,7 @@ module.exports = {
"no-wx-for-with-wx-if": require("./rules/no-wx-for-with-wx-if"),
"no-wx-if-string": require("./rules/no-wx-if-string"),
quotes: require("./rules/quotes"),
+ "report-interpolation-error": require("./rules/report-interpolation-error"),
"report-wxs-syntax-error": require("./rules/report-wxs-syntax-error"),
"report-wxml-syntax-error": require("./rules/report-wxml-syntax-error"),
"required-attributes": require("./rules/required-attributes"),
diff --git a/lib/rules/report-interpolation-error.js b/lib/rules/report-interpolation-error.js
new file mode 100644
index 0000000..8cc507d
--- /dev/null
+++ b/lib/rules/report-interpolation-error.js
@@ -0,0 +1,61 @@
+module.exports = {
+ /** @type {import('eslint').Rule.RuleMetaData} */
+ meta: {
+ type: "problem",
+ docs: {
+ description: "report interpolation error",
+ categories: [],
+ url: "https://eslint-plugin-wxml.js.org/rules/report-interpolation-error.html",
+ },
+ fixable: null,
+ messages: {
+ interpolationError: "{{error}}",
+ },
+ schema: [],
+ },
+
+ /** @param {import('eslint').Rule.RuleContext} context */
+ create(context) {
+ return {
+ WXInterpolation(node) {
+ let espreeParser;
+ if (!(node && node.value)) {
+ return;
+ }
+ try {
+ // eslint-disable-next-line node/no-extraneous-require
+ espreeParser = require("espree");
+ } catch (_) {
+ // ...
+ }
+ if (espreeParser) {
+ try {
+ espreeParser.parse(node.value, {
+ ecmaVersion: espreeParser.latestEcmaVersion,
+ });
+ } catch (error) {
+ try {
+ espreeParser.parse(`({${node.value}})`, {
+ ecmaVersion: espreeParser.latestEcmaVersion,
+ });
+ } catch (_) {
+ try {
+ espreeParser.parse(`(${node.value})`, {
+ ecmaVersion: espreeParser.latestEcmaVersion,
+ });
+ } catch (_) {
+ context.report({
+ node,
+ messageId: "interpolationError",
+ data: {
+ error: error.message,
+ },
+ });
+ }
+ }
+ }
+ }
+ },
+ };
+ },
+};
diff --git a/package-lock.json b/package-lock.json
index 848e9db..7f2dbb2 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -90,9 +90,9 @@
"dev": true
},
"@wxml/parser": {
- "version": "0.3.2",
- "resolved": "https://registry.npmjs.org/@wxml/parser/-/parser-0.3.2.tgz",
- "integrity": "sha512-CW+So8MlXtyrt8Rb8IFDv5QZ3MkodqtypwHA4/bzRbcae5SlCXr4XhOoKJxViPvg8vJhKSlPJ+QJfc9UfP7Xvw=="
+ "version": "0.4.0",
+ "resolved": "https://registry.npmjs.org/@wxml/parser/-/parser-0.4.0.tgz",
+ "integrity": "sha512-pS0OPyKzCOhCPGlcfO9IDLZbqH4485bPdGDqaa+hYnI+cY/OW+GN4J88XpfdzM8wXJcJShFZy5F6MTUr2rysXg=="
},
"acorn": {
"version": "7.4.1",
diff --git a/package.json b/package.json
index 35775f2..6a33218 100644
--- a/package.json
+++ b/package.json
@@ -34,6 +34,6 @@
"prettier": "^2.5.1"
},
"dependencies": {
- "@wxml/parser": "^0.3.2"
+ "@wxml/parser": "^0.4.0"
}
}
diff --git a/tests/rules/report-interpolation-error.js b/tests/rules/report-interpolation-error.js
new file mode 100644
index 0000000..df5d20f
--- /dev/null
+++ b/tests/rules/report-interpolation-error.js
@@ -0,0 +1,147 @@
+const RuleTester = require("eslint").RuleTester;
+const rule = require("../../lib/rules/report-interpolation-error");
+
+const tester = new RuleTester({
+ parser: require.resolve("@wxml/parser"),
+});
+
+tester.run("report-interpolation-error", rule, {
+ valid: [
+ {
+ filename: "interpolation.wxml",
+ code: ` {{23}} `,
+ },
+ {
+ filename: "interpolation.wxml",
+ code: ` {{ show ? 23 : ''}} `,
+ },
+ {
+ filename: "",
+ code: `
+
+ `,
+ },
+ {
+ filename: "interpolation.wxml",
+ code: ` {{ }} `,
+ },
+ {
+ filename: "interpolation.wxml",
+ code: `
+
+ `,
+ },
+ {
+ filename: "interpolation.wxml",
+ code: ` {{ a + b }} `,
+ },
+ {
+ filename: "interpolation.wxml",
+ code: ``,
+ },
+ {
+ filename: "interpolation.wxml",
+ code: `{{"hello" + name}}`,
+ },
+ {
+ filename: "interpolation.wxml",
+ code: `{{object.key}} {{array[0]}}`,
+ },
+ {
+ filename: "interpolation.wxml",
+ code: ` {{item}} `,
+ },
+ {
+ filename: "interpolation.wxml",
+ code: ``,
+ },
+ {
+ filename: "interpolation.wxml",
+ code: `
+
+ `,
+ },
+ {
+ filename: "interpolation.wxml",
+ code: ``,
+ },
+ {
+ filename: "interpolation.wxml",
+ code: `ext_params_click="{{ { goods_id: log.goodsId, exps: log.stringifyExps } }}"`,
+ },
+ ],
+ invalid: [
+ {
+ filename: "interpolation.wxml",
+ code: ` {{ show ? 23 : }} `,
+ errors: [
+ {
+ messageId: "interpolationError",
+ data: {
+ error: "Unexpected token",
+ },
+ },
+ ],
+ },
+ {
+ filename: "interpolation.wxml",
+ code: ` {{ show 23 : }} `,
+ errors: [
+ {
+ messageId: "interpolationError",
+ data: {
+ error: "Unexpected token 23",
+ },
+ },
+ ],
+ },
+ {
+ filename: "interpolation.wxml",
+ code: ` {{ a + }} `,
+ errors: [
+ {
+ messageId: "interpolationError",
+ data: {
+ error: "Unexpected token",
+ },
+ },
+ ],
+ },
+ {
+ filename: "interpolation.wxml",
+ code: ` {{ ..a, a: }} `,
+ errors: [
+ {
+ messageId: "interpolationError",
+ data: {
+ error: "Unexpected token .",
+ },
+ },
+ ],
+ },
+ {
+ filename: "interpolation.wxml",
+ code: ``,
+ errors: [
+ {
+ messageId: "interpolationError",
+ data: {
+ error: "Unexpected token",
+ },
+ },
+ ],
+ }
+ ],
+});
diff --git a/tests/rules/report-wxml-syntax-error.js b/tests/rules/report-wxml-syntax-error.js
index 822ff12..5b613ca 100644
--- a/tests/rules/report-wxml-syntax-error.js
+++ b/tests/rules/report-wxml-syntax-error.js
@@ -66,8 +66,7 @@ tester.run("report-wxml-syntax-error", rule, {
{
messageId: "wxmlError",
data: {
- error:
- "Expecting token of type --> EOF <-- but found --> 'var data = {}; module.exports = { data: data } ' <--",
+ error: "Expecting token of type --> EOF <-- but found --> '' <--",
},
},
],
@@ -80,7 +79,13 @@ tester.run("report-wxml-syntax-error", rule, {
messageId: "wxmlError",
data: {
error:
- "Expecting token of type --> EOF <-- but found --> '{{ a > ' }} {{}}' <--",
+ "unexpected character: ->'<- at offset: 30, skipped 1 characters.",
+ },
+ },
+ {
+ messageId: "wxmlError",
+ data: {
+ error: "Expecting token of type --> EOF <-- but found --> '' <--",
},
},
],
diff --git a/website/docs/rules/README.md b/website/docs/rules/README.md
index 3e17856..94e32a2 100644
--- a/website/docs/rules/README.md
+++ b/website/docs/rules/README.md
@@ -35,6 +35,7 @@ sidebarDepth: 0
| [Deprecated] [wxml/no-wx-for-with-wx-if](./no-wx-for-with-wx-if.md) | ~~avoid [error](https://developers.weixin.qq.com/community/develop/doc/00082a556fcb0810a6b7e2eee5b800) when you use `wx:for` with `wx:if/wx:elif/wx:else` at same tag~~ | | |
| [wxml/no-wx-if-string](./no-wx-if-string.md) | avoid unexpected result when you use invalid boolean interpolation as `wx:if/wx:elif`'s value | :star: :star: :star: | |
| [wxml/quotes](./quotes.md) | force using same quotes style in project, `'` or `"` | :star: | |
+| [wxml/report-interpolation-error](./report-interpolation-error.md) | check `interpolation` syntax error via [`@wxml/parser`](https://github.com/wxmlfile/wxml-parser) | :star: :star: :star: | |
| [wxml/report-wxml-syntax-error](./report-wxml-syntax-error.md) | check `wxml` syntax error via [`@wxml/parser`](https://github.com/wxmlfile/wxml-parser) | :star: | |
| [wxml/report-wxs-syntax-error](./report-wxml-syntax-error.md) | check inline `wxs` syntax error via [`@wxml/parser`](https://github.com/wxmlfile/wxml-parser) | :star: | |
| [wxml/required-attributes](./required-attributes.md) | using custom config to force team member write the required attributes in wxml | :star: :star: | |
diff --git a/website/docs/rules/report-interpolation-error.md b/website/docs/rules/report-interpolation-error.md
new file mode 100644
index 0000000..60d24d5
--- /dev/null
+++ b/website/docs/rules/report-interpolation-error.md
@@ -0,0 +1,52 @@
+---
+sidebarDepth: 0
+title: wxml/report-interpolation-error
+---
+
+# wxml/report-interpolation-error
+
+### Backgroud
+
+::: tip {{}} interpolation
+
+> Mustache style [interpolation]([https://developers.weixin.qq.com/miniprogram/dev/reference/wxml/data.html]) in wxml
+
+`eslint-plugin-wxml` using `@wxml/parser` as parser to parse interpolation content, it provide `interpolation` syntax error message. If you think this rules contain `bug`, please report it by [github issue](https://github.com/wxmlfile/eslint-plugin-wxml/issues).
+
+:::
+
+## Motivation
+
+hint interpolation syntax error in development time, save developer's time.
+
+
+```wxml
+
+
+ {{ a + }}
+
+```
+
+
+::: tip 💡 tips
+
+You can edit code via online editor, it's online REPL, try to fix eslint problem !
+
+:::
+
+## Config
+
+No special options, normal config is ok
+
+```json
+{ "wxml/report-interpolation-error": "error" }
+```
+
+## Version
+
+This rule was introduced in eslint-plugin-wxml `v0.7.0`
+
+## Implementation
+
+- [Rule Source Code](https://github.com/wxmlfile/eslint-plugin-wxml/tree/main/lib/rules/report-interpolation-error.js)
+- [Test Source Code](https://github.com/wxmlfile/eslint-plugin-wxml/tree/main/tests/rules/report-interpolation-error.js)
diff --git a/website/docs/rules/report-wxml-syntax-error.md b/website/docs/rules/report-wxml-syntax-error.md
index 1243a19..f52baff 100644
--- a/website/docs/rules/report-wxml-syntax-error.md
+++ b/website/docs/rules/report-wxml-syntax-error.md
@@ -9,7 +9,7 @@ title: wxml/report-wxml-syntax-error
::: tip wxml
-`eslint-plugin-wxml` using `@wxml/parser` ad parser to parse `wxml` source code, it provide `wxml` syntax error message. If you think this rules contain `bug`, please report it by [github issue](https://github.com/wxmlfile/eslint-plugin-wxml/issues).
+`eslint-plugin-wxml` using `@wxml/parser` as parser to parse `wxml` source code, it provide `wxml` syntax error message. If you think this rules contain `bug`, please report it by [github issue](https://github.com/wxmlfile/eslint-plugin-wxml/issues).
:::