Skip to content

Commit

Permalink
build: use oxlint --rules --format=json for building rules (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix authored Jan 5, 2025
1 parent 2a133f2 commit e7c2dff
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 655 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/bump_oxlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ jobs:
OXLINT_VERSION: ${{ inputs.version }}
run: |
pnpm install oxlint@${OXLINT_VERSION}
pnpm run clone ${OXLINT_VERSION}
pnpm run generate # Generate rules from source code
pnpm run generate # Generate rules
pnpm run format # run prettier over it
- name: Test and update snapshot
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ jobs:

- uses: ./.github/actions/pnpm

- name: Clone oxc_linter project
run: pnpm run clone

- name: Remove current generated code
run: rm -r ./src/generated/

Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,21 @@ You need to install both the [oxc](https://marketplace.visualstudio.com/items?it

## Contributing

sparse clone the oxlint repository to have a local copy
### Generate rules

Generates the rules from installed oxlint version

```shell
pnpm clone
pnpm generate
pnpm format
```

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.
### Test

Tests the source code

```shell
pnpm generate
pnpm test
```

## License
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"scripts": {
"prepare": "husky",
"generate": "node --import @oxc-node/core/register ./scripts/generate.ts",
"clone": "node --import @oxc-node/core/register ./scripts/sparse-clone.ts",
"build": "vite build",
"lint": "npx oxlint --tsconfig=tsconfig.json && npx eslint --flag unstable_ts_config",
"format": "npx prettier --write .",
Expand Down
21 changes: 0 additions & 21 deletions scripts/constants.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
import path from 'node:path';
import { aliasPluginNames } from '../src/constants.js';

const __dirname = new URL('.', import.meta.url).pathname;

export const TARGET_DIRECTORY = path.resolve(__dirname, '..', '.oxc_sparse');
export const VERSION_PREFIX = 'oxlint_v';
export const SPARSE_CLONE_DIRECTORY = 'crates/oxc_linter/src';

// these are the rules that don't have a direct equivalent in the eslint rules
export const ignoreScope = new Set(['oxc', 'deepscan', 'security']);

// these are the rules that are not fully implemented in oxc
export const ignoreCategories = new Set(['nursery']);

export function convertScope(scope: string) {
return Reflect.has(aliasPluginNames, scope)
? aliasPluginNames[scope as 'eslint']
: scope.replace('_', '-');
}

export function prefixScope(scope: string) {
const _scope = convertScope(scope);

return _scope ? `${_scope}/` : '';
}
8 changes: 1 addition & 7 deletions scripts/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ import { traverseRules } from './traverse-rules.js';

const __dirname = new URL('.', import.meta.url).pathname;

const { successResultArray, failureResultArray } = await traverseRules();

if (failureResultArray.length > 0) {
console.error(
`Failed to generate rules for the following rules ${JSON.stringify(failureResultArray)}`
);
}
const successResultArray = traverseRules();

const rulesGenerator = new RulesGenerator(successResultArray);
const configGenerator = new ConfigGenerator(successResultArray);
Expand Down
95 changes: 0 additions & 95 deletions scripts/sparse-clone.ts

This file was deleted.

Loading

0 comments on commit e7c2dff

Please sign in to comment.