Skip to content

Commit

Permalink
chore: get rules from tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Jan 13, 2024
1 parent 9d4105f commit 1a962f3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion scripts/generate-rules.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import axios from 'axios'
import { writeFileSync } from 'node:fs'
import path from 'node:path'
import { getLatestOxlintVersion } from './oxlint-version.js';


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

const oxlintRulesUrl = "https://raw.githubusercontent.com/oxc-project/oxc/main/crates/oxc_linter/src/rules.rs"


const oxlintVersion = await getLatestOxlintVersion();

console.log("Generating rules for " + oxlintVersion)

const oxlintRulesUrl = `https://raw.githubusercontent.com/oxc-project/oxc/${oxlintVersion}/crates/oxc_linter/src/rules.rs`;
const RulesRe = /oxc_macros::declare_all_lint_rules.*{([^*]*),\s*}/gm
const rulesMap = new Map<string, Array<string>>()
const ignoreScope = new Set(["oxc", "deepscan"])
Expand Down
14 changes: 14 additions & 0 deletions scripts/oxlint-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import axios from "axios";

export async function getLatestOxlintVersion() {
const tagsUrl = 'https://api.github.com/repos/oxc-project/oxc/tags';
const response = await axios.get(tagsUrl);
const tags = response.data.map((tag: any) => tag.name);
const oxlintTags: string[] = tags.filter((tag: string) => tag.startsWith('oxlint_v'));
const latestVersion = oxlintTags.slice(1).reduce((latest: string, current: string) => {
const latestNumber = parseInt(latest.replace('oxlint_v', ''));
const currentNumber = parseInt(current.replace('oxlint_v', ''));
return currentNumber > latestNumber ? current : latest;
}, oxlintTags[0]);
return latestVersion;
}

0 comments on commit 1a962f3

Please sign in to comment.