Skip to content

Commit

Permalink
Use Git Sparse checkout to make it easier to get the local rules (oxc…
Browse files Browse the repository at this point in the history
…-project#64)

* Make prettier work with this repo

* sparse clone and remove axios dependency

* make code more readable, add spaces.

* traverse all rules and return them grouped, preparing for "recommended/restriction" and "recommended/correctness" etc ...

* fix snapshot

* rules by category / rules by scope

* Add all the configs

* use vite to build ESM and CJS instead of duplicating.

* only provide coverage for the files we care about

* more tests, more cleanup

* new build. should this really be committed though

* feat: update

* chore: downgrades eslint

---------

Co-authored-by: Qing <[email protected]>
Co-authored-by: Dunqing <[email protected]>
  • Loading branch information
3 people authored May 20, 2024
1 parent b0d5e86 commit 9a17ad9
Show file tree
Hide file tree
Showing 50 changed files with 5,003 additions and 1,022 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/bump_oxlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
pull_request:
types: [opened, synchronize]
branches:
- "renovate/oxlint-**"
- 'renovate/oxlint-**'
paths:
- package.json

Expand All @@ -30,7 +30,7 @@ jobs:
with:
node-version-file: .node-version
cache: pnpm
registry-url: "https://registry.npmjs.org"
registry-url: 'https://registry.npmjs.org'

- name: Install Dependencies
run: pnpm i
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Bump oxlint

on:
pull_request:
types:
- labeled

permissions:
pull-requests: write
contents: write

env:
OXLINT_PACKAGE_NAME: oxlint

jobs:
bump-oxlint-rules:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]' && github.event.label.name == 'dependencies'
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/checkout@v4
if: contains(steps.metadata.outputs.dependency-names, env.OXLINT_PACKAGE_NAME)
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Install pnpm
if: contains(steps.metadata.outputs.dependency-names, env.OXLINT_PACKAGE_NAME)
uses: pnpm/action-setup@v2

- name: Set node
if: contains(steps.metadata.outputs.dependency-names, env.OXLINT_PACKAGE_NAME)
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: pnpm
registry-url: 'https://registry.npmjs.org'

- name: Install Dependencies
if: contains(steps.metadata.outputs.dependency-names, env.OXLINT_PACKAGE_NAME)
run: pnpm i

- name: Bump oxlint rules
if: contains(steps.metadata.outputs.dependency-names, env.OXLINT_PACKAGE_NAME)
run: |
# Generate rules from latest oxlint
pnpm run generate
# Update test snapshots
pnpm run test -u
# Commit and push changes
git config --global user.name "dependabot[bot]"
git config --global user.email "49699333+dependabot[bot]@users.noreply.github.com"
git commit -am "feat(oxlint): bump oxlint rules"
git push
# Edit title message for changelog purpose
gh pr edit "$PR_URL" --title "feat(oxlint): bump oxlint rules"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release
on:
push:
tags:
- "v*"
- 'v*'

permissions:
contents: write
Expand All @@ -24,7 +24,7 @@ jobs:
with:
node-version-file: .node-version
cache: pnpm
registry-url: "https://registry.npmjs.org"
registry-url: 'https://registry.npmjs.org'

- run: npx changelogithub
continue-on-error: true
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,5 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

.oxc_sparse
2 changes: 2 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
pnpm = "9.0.6"
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
// Editor values
"editor.formatOnSave": true,
// Eslint Configuration
"eslint.workingDirectories": ["."],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"eslint.validate": ["javascript", "typescript"]
}
60 changes: 58 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ This plugin is optimized for flat config usage (eslint >= 9.0). See [here](https

```js
// eslint.config.js
import oxlint from "eslint-plugin-oxlint";
import oxlint from 'eslint-plugin-oxlint';
export default [
...// other plugins
oxlint.configs["flat/recommended"], // oxlint should be the last one
oxlint.configs['flat/recommended'], // oxlint should be the last one
];
```

Expand Down Expand Up @@ -57,10 +57,66 @@ And then you can add the following script to your `package.json`:
}
```

## All Configs

```js
configs: {
// recmmended only contains the `correctness` category
recommended: { plugins: [Array], rules: [Object] },
'flat/recommended': { rules: [Object] },

// all rules available
all: { plugins: [Array], rules: [Object] },
'flat/all': { rules: [Object] },

// turn eslint rules off by plugin
'flat/eslint': { rules: [Object] },
'flat/import': { rules: [Object] },
'flat/jest': { rules: [Object] },
'flat/jsdoc': { rules: [Object] },
'flat/jsx-a11y': { rules: [Object] },
'flat/nextjs': { rules: [Object] },
'flat/react': { rules: [Object] },
'flat/react-perf': { rules: [Object] },
'flat/tree-shaking': { rules: [Object] },
'flat/typescript': { rules: [Object] },
'flat/unicorn': { rules: [Object] },

// turn eslint rules off by oxlint category
'flat/pedantic': { rules: [Object] },
'flat/nursery': { rules: [Object] },
'flat/style': { rules: [Object] },
'flat/correctness': { rules: [Object] },
'flat/restriction': { rules: [Object] },
'flat/suspicious': { rules: [Object] }
}
```

## VSCode Support

You need to install both the [oxc](https://marketplace.visualstudio.com/items?itemName=oxc.oxc-vscode) and [eslint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) extensions

## Contributing

sparse clone the oxlint repository to have a local copy

```shell
pnpm clone
```

generates the rules from the sparse cloned Rust library, only for the latest version,
new rules that haven't been released will not be included.

```shell
pnpm generate
```

build cjs and esm versions of the library

```shell
pnpm build
```

## License

[MIT](https://github.com/Dunqing/eslint-plugin-oxlint/blob/main/LICENSE)
18 changes: 9 additions & 9 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import oxlint from "./index.cjs";
import unicorn from "eslint-plugin-unicorn";
import { FlatCompat } from "@eslint/eslintrc";
import eslint from "@eslint/js";
import eslintConfigPrettier from "eslint-config-prettier";
import oxlint from './lib/index.cjs';
import unicorn from 'eslint-plugin-unicorn';
import { FlatCompat } from '@eslint/eslintrc';
import eslint from '@eslint/js';
import eslintConfigPrettier from 'eslint-config-prettier';

const __dirname = new URL(".", import.meta.url).pathname;
const __dirname = new URL('.', import.meta.url).pathname;
const compat = new FlatCompat({ resolvePluginsRelativeTo: __dirname });

export default [
eslint.configs.recommended,
unicorn.configs["flat/recommended"],
...compat.extends("plugin:@typescript-eslint/recommended"),
unicorn.configs['flat/recommended'],
...compat.extends('plugin:@typescript-eslint/recommended'),
eslintConfigPrettier,
oxlint.configs["flat/recommended"],
oxlint.configs['flat/all'],
];
19 changes: 0 additions & 19 deletions index.cjs

This file was deleted.

12 changes: 0 additions & 12 deletions index.d.ts

This file was deleted.

19 changes: 0 additions & 19 deletions index.js

This file was deleted.

10 changes: 0 additions & 10 deletions index.spec.ts

This file was deleted.

26 changes: 26 additions & 0 deletions lib/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';
const rulesByScope = require('./rules-by-scope.cjs');
const rulesByCategory = require('./rules-by-category.cjs');
const utils = require('./utils.cjs');
const allRules = Object.assign({}, ...Object.values(rulesByScope));
const index = {
configs: {
recommended: {
plugins: ['oxlint'],
rules: rulesByCategory.correctnessRules,
},
all: {
plugins: ['oxlint'],
rules: allRules,
},
'flat/all': {
rules: allRules,
},
'flat/recommended': {
rules: rulesByCategory.correctnessRules,
},
...utils.createFlatRulesConfig(rulesByScope),
...utils.createFlatRulesConfig(rulesByCategory),
},
};
module.exports = index;
Loading

0 comments on commit 9a17ad9

Please sign in to comment.