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

feat: support flat config #65

Merged
merged 8 commits into from
Apr 20, 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
30 changes: 17 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,24 @@ jobs:
- run: npm run lint
- run: npm run test

flat_config_test:
name: Test eslint-plugin-wxml with flat config
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with: {node-version: '${{ env.NODE_VERSION }}'}
- name: Set working directory
working-directory: tests/flatconfig
run: |
pwd
npm install --force
npm list --depth=0
npm run test

node_tests:
name: 'Test eslint-plugin-wxml on ${{matrix.os}} with node${{matrix.node}}'
name: 'Test on ${{matrix.os}} with node${{matrix.node}}'
strategy:
matrix:
os: [ubuntu-latest]
Expand All @@ -78,18 +94,6 @@ jobs:
with:
# The Node.js version to configure
node-version: ${{ matrix.node }}
# Caching dependencies to speed up workflows
- name: Get npm cache directory
id: npm-cache-dir
run: |
echo "::set-output name=dir::$(npm config get cache)"
- 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 }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install npm dependencies
run: npm install
- name: Print put node & npm version
Expand Down
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
.idea/
.vscode/

node_modules
.DS_Store
website
docs
tools
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.8.0] - 2024-04-20
### Added
- Support [flat config](https://eslint.org/docs/latest/use/configure/migration-guide)

## [0.7.5] - 2022-08-21
### Changed
- Add `disableAttrs` and `skipAttrs` config support for rule `forbid-tags`
Expand Down
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,36 @@ $ yarn add eslint-plugin-wxml -D

## Basic Usage

### change your eslintrc config
### Configuration (`eslint.config.mjs`)

Use `eslint.config.mjs` file to configure rules. This is the default in ESLint v9, but can be used starting from ESLint v8.57.0. See also: <https://eslint.org/docs/latest/use/configure/configuration-files-new>.

Example **eslint.config.mjs**:

```js
import wxml from "eslint-plugin-wxml";
import wxmlParser from "@wxml/parser";

export default [
{
files: ["**/*.wxml"],
plugins: {
wxml: wxml,
},
languageOptions: {
parser: wxmlParser,
},
rules: {
"wxml/report-wxml-syntax-error": "error",
},
},
];
```

### Configuration (`.eslintrc`)

Use `.eslintrc.*` file to configure rules. See also: [https://eslint.org/docs/v8.x/use/configure/configuration-files](https://eslint.org/docs/v8.x/use/configure/configuration-files).

> .eslintrc .eslintrc.yml .eslinrc.json .eslintrc.js

```diff
+ "overrides": [
Expand Down
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"use strict";

module.exports = {
meta: {
name: "eslint-plugin-wxml",
version: "0.8.0",
},
rules: {
"colon-style-event-binding": require("./rules/colon-style-event-binding"),
"empty-tag-self-closing": require("./rules/empty-tag-self-closing"),
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-wxml",
"version": "0.7.5",
"version": "0.8.0",
"description": "eslint plugin for wxml",
"main": "lib/index.js",
"type": "commonjs",
Expand All @@ -24,7 +24,7 @@
"test": "mocha \"tests/**/*.js\" --reporter dot"
},
"peerDependencies": {
"eslint": "^7.0.0 || ^8.0.0"
"eslint": "^7.0.0 || ^8.0.0 || ^9.0.0"
},
"devDependencies": {
"eslint": "^7.32.0",
Expand Down
3 changes: 3 additions & 0 deletions tests/flatconfig/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.DS_Store
package-lock.json
17 changes: 17 additions & 0 deletions tests/flatconfig/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import wxml from "eslint-plugin-wxml";
import wxmlParser from "@wxml/parser";

export default [
{
files: ["**/*.wxml"],
plugins: {
wxml: wxml,
},
languageOptions: {
parser: wxmlParser,
},
rules: {
"wxml/colon-style-event-binding": "error",
},
},
];
18 changes: 18 additions & 0 deletions tests/flatconfig/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "flat-config-compat",
"version": "1.0.0",
"description": "tests for eslint's flat config",
"main": "index.js",
"scripts": {
"test": "eslint ."
},
"keywords": [
"wxml"
],
"author": "chenleicoder@gmail.com",
"license": "MIT",
"dependencies": {
"eslint": "^9.0.0",
"eslint-plugin-wxml": "^0.8.0"
}
}
13 changes: 13 additions & 0 deletions tests/flatconfig/test.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- ✓ GOOD -->
<view bind:tap="clickhandler" />
<view mut-bind:tap="clickhandler" />
<view catch:tap="clickhandler" />
<view capture-catch:tap="clickhandler" />
<view capture-bind:tap="clickhandler" />

<!-- ✗ BAD -->
<view bindtap="clickhandler" />

Check failure on line 9 in tests/flatconfig/test.wxml

View workflow job for this annotation

GitHub Actions / Test eslint-plugin-wxml with flat config

missng ":" between bind and tap
<view mut-bindtap="clickhandler" />

Check failure on line 10 in tests/flatconfig/test.wxml

View workflow job for this annotation

GitHub Actions / Test eslint-plugin-wxml with flat config

missng ":" between mut-bind and tap
<view catchtap="clickhandler" />

Check failure on line 11 in tests/flatconfig/test.wxml

View workflow job for this annotation

GitHub Actions / Test eslint-plugin-wxml with flat config

missng ":" between catch and tap
<view capture-catchtap="clickhandler" />

Check failure on line 12 in tests/flatconfig/test.wxml

View workflow job for this annotation

GitHub Actions / Test eslint-plugin-wxml with flat config

missng ":" between capture-catch and tap
<view capture-bindtap="clickhandler" />

Check failure on line 13 in tests/flatconfig/test.wxml

View workflow job for this annotation

GitHub Actions / Test eslint-plugin-wxml with flat config

missng ":" between capture-bind and tap
30 changes: 29 additions & 1 deletion website/docs/user-guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,35 @@ pnpm add -D eslint eslint-plugin-wxml

## :book: Usage

### Configuration
### Configuration (`eslint.config.mjs`)

Use `eslint.config.mjs` file to configure rules. This is the default in ESLint v9, but can be used starting from ESLint v8.57.0. See also: <https://eslint.org/docs/latest/use/configure/configuration-files-new>.

Example **eslint.config.mjs**:

```js
import wxml from "eslint-plugin-wxml";
import wxmlParser from "@wxml/parser";

export default [
{
files: ["**/*.wxml"],
plugins: {
wxml: wxml,
},
languageOptions: {
parser: wxmlParser,
},
rules: {
"wxml/colon-style-event-binding": "error",
},
},
];
```

See [the rule list](../rules/README.md) to get the `extends` &amp; `rules` that this plugin provides.

### Configuration (`.eslintrc`)

Use `.eslintrc.*` file to configure rules. See also: [https://eslint.org/docs/user-guide/configuring](https://eslint.org/docs/user-guide/configuring).

Expand Down
Loading