Skip to content

Commit a8e5181

Browse files
committed
chore(infra): dogfooding oxfmt (#14979)
Fixes #14803 - Added `oxfmt` and `oxfmtrc.jsonc` - Remove `dprint` plugin and useless ignore paths - Apply `dprint` again - Apply `oxfmt`
1 parent 13060c8 commit a8e5181

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+771
-801
lines changed

.github/scripts/generate-benchmark-matrix.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function checkGlobalChanges(changedFiles) {
3131
}
3232

3333
for (const file of changedFiles) {
34-
if (GLOBAL_FILES.some(globalFile => file === globalFile || file.endsWith(`/${globalFile}`))) {
34+
if (GLOBAL_FILES.some((globalFile) => file === globalFile || file.endsWith(`/${globalFile}`))) {
3535
console.error(`Global file changed: ${file}`);
3636
return true;
3737
}
@@ -89,14 +89,14 @@ function isComponentAffected(component, changedFiles) {
8989
// Check if any dependency files changed
9090
for (const dep of dependencies) {
9191
const depPath = `crates/${dep}/`;
92-
if (changedFiles.some(file => file.startsWith(depPath))) {
92+
if (changedFiles.some((file) => file.startsWith(depPath))) {
9393
console.error(` Component ${component} affected by changes in ${depPath}`);
9494
return true;
9595
}
9696
}
9797

9898
// Check benchmark and common task files
99-
if (changedFiles.some(file => file.startsWith('tasks/benchmark/') || file.startsWith('tasks/common/'))) {
99+
if (changedFiles.some((file) => file.startsWith('tasks/benchmark/') || file.startsWith('tasks/common/'))) {
100100
console.error(` Component ${component} affected by benchmark/common file changes`);
101101
return true;
102102
}
@@ -113,7 +113,7 @@ async function determineAffectedComponents() {
113113

114114
// Manual trigger - run all benchmarks
115115
if (changedFiles === null) {
116-
return ALL_COMPONENTS.map(component => ({
116+
return ALL_COMPONENTS.map((component) => ({
117117
component,
118118
feature: getFeatureForComponent(component),
119119
}));
@@ -122,7 +122,7 @@ async function determineAffectedComponents() {
122122
// Check for global changes
123123
if (checkGlobalChanges(changedFiles)) {
124124
console.error('Global changes detected - will run all benchmarks');
125-
return ALL_COMPONENTS.map(component => ({
125+
return ALL_COMPONENTS.map((component) => ({
126126
component,
127127
feature: getFeatureForComponent(component),
128128
}));
@@ -144,7 +144,7 @@ async function determineAffectedComponents() {
144144
if (affectedComponents.length === 0) {
145145
console.error('\nNo components were affected by the changes');
146146
} else {
147-
console.error(`\nAffected components: ${affectedComponents.map(obj => obj.component).join(', ')}`);
147+
console.error(`\nAffected components: ${affectedComponents.map((obj) => obj.component).join(', ')}`);
148148
}
149149

150150
return affectedComponents;
@@ -165,15 +165,15 @@ async function main() {
165165
if (affectedComponents.length === 0) {
166166
console.error('::notice title=No benchmarks to run::No components were affected by the changes');
167167
} else {
168-
const componentNames = affectedComponents.map(obj => obj.component).join(', ');
168+
const componentNames = affectedComponents.map((obj) => obj.component).join(', ');
169169
console.error(`::notice title=Running benchmarks::Affected components: ${componentNames}`);
170170
}
171171

172172
process.exit(0);
173173
} catch (error) {
174174
console.error('Error generating benchmark matrix:', error);
175175
// On error, run all benchmarks as a fallback
176-
const fallbackMatrix = ALL_COMPONENTS.map(component => ({
176+
const fallbackMatrix = ALL_COMPONENTS.map((component) => ({
177177
component,
178178
feature: getFeatureForComponent(component),
179179
}));

.github/scripts/get-changed-files.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function githubApi(path) {
2020
path,
2121
headers: {
2222
'User-Agent': 'oxc-changed-files',
23-
'Accept': 'application/vnd.github.v3+json',
23+
Accept: 'application/vnd.github.v3+json',
2424
},
2525
};
2626

@@ -30,17 +30,19 @@ function githubApi(path) {
3030
options.headers['Authorization'] = `token ${token}`;
3131
}
3232

33-
https.get(options, (res) => {
34-
let data = '';
35-
res.on('data', chunk => data += chunk);
36-
res.on('end', () => {
37-
if (res.statusCode === 200) {
38-
resolve(JSON.parse(data));
39-
} else {
40-
reject(new Error(`GitHub API error: ${res.statusCode} ${data}`));
41-
}
42-
});
43-
}).on('error', reject);
33+
https
34+
.get(options, (res) => {
35+
let data = '';
36+
res.on('data', (chunk) => (data += chunk));
37+
res.on('end', () => {
38+
if (res.statusCode === 200) {
39+
resolve(JSON.parse(data));
40+
} else {
41+
reject(new Error(`GitHub API error: ${res.statusCode} ${data}`));
42+
}
43+
});
44+
})
45+
.on('error', reject);
4446
});
4547
}
4648

@@ -72,12 +74,12 @@ async function getChangedFiles() {
7274
// For PR, use GitHub API to get changed files
7375
console.error(`Getting changed files for PR #${prNumber}`);
7476
const prFiles = await githubApi(`/repos/${repository}/pulls/${prNumber}/files?per_page=100`);
75-
files = prFiles.map(f => f.filename);
77+
files = prFiles.map((f) => f.filename);
7678
} else if (sha && repository) {
7779
// For push to main, get the commit and compare with parent
7880
console.error(`Getting changed files for commit ${sha}`);
7981
const commit = await githubApi(`/repos/${repository}/commits/${sha}`);
80-
files = commit.files ? commit.files.map(f => f.filename) : [];
82+
files = commit.files ? commit.files.map((f) => f.filename) : [];
8183
} else {
8284
// No valid parameters for API calls
8385
console.error('Error: Missing required environment variables for GitHub API');
@@ -91,7 +93,7 @@ async function getChangedFiles() {
9193
}
9294

9395
console.error(`Changed files (${files.length}):`);
94-
files.forEach(f => console.error(` - ${f}`));
96+
files.forEach((f) => console.error(` - ${f}`));
9597

9698
return files;
9799
}
@@ -101,11 +103,11 @@ module.exports = { getChangedFiles };
101103
// If run directly as a script, output changed files as JSON
102104
if (require.main === module) {
103105
getChangedFiles()
104-
.then(files => {
106+
.then((files) => {
105107
console.log(JSON.stringify(files));
106108
process.exit(0);
107109
})
108-
.catch(error => {
110+
.catch((error) => {
109111
console.error('Error:', error);
110112
console.log(JSON.stringify(null));
111113
process.exit(1);

.github/scripts/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function exec(command) {
2929
*/
3030
function getCrateDependencies(packages, options = {}) {
3131
const pkgs = Array.isArray(packages) ? packages : [packages];
32-
const packageArgs = pkgs.map(pkg => `-p ${pkg}`).join(' ');
32+
const packageArgs = pkgs.map((pkg) => `-p ${pkg}`).join(' ');
3333

3434
let command = `cargo tree ${packageArgs} -f "{lib}" -e normal --no-dedupe --prefix none`;
3535

@@ -51,7 +51,7 @@ function getCrateDependencies(packages, options = {}) {
5151
}
5252

5353
// Filter out the queried packages themselves
54-
return output.split('\n').filter(dep => dep && !pkgs.includes(dep));
54+
return output.split('\n').filter((dep) => dep && !pkgs.includes(dep));
5555
}
5656

5757
/**
@@ -69,15 +69,15 @@ function checkFilesAffectCrates(changedFiles, crates, additionalPaths = []) {
6969
// Check if any changed file affects a crate
7070
for (const crate of crates) {
7171
const cratePath = `crates/${crate}/`;
72-
if (changedFiles.some(file => file.startsWith(cratePath))) {
72+
if (changedFiles.some((file) => file.startsWith(cratePath))) {
7373
console.error(`File affects crate ${crate}`);
7474
return true;
7575
}
7676
}
7777

7878
// Check additional paths
7979
for (const path of additionalPaths) {
80-
if (changedFiles.some(file => file.startsWith(path))) {
80+
if (changedFiles.some((file) => file.startsWith(path))) {
8181
console.error(`File affects path ${path}`);
8282
return true;
8383
}

.github/workflows/autofix.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
steps:
2020
- uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1
2121

22+
- uses: oxc-project/setup-node@fdbf0dfd334c4e6d56ceeb77d91c76339c2a0885 # v1.0.4
23+
2224
- name: Restore dprint plugin cache
2325
id: cache-restore
2426
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0

apps/oxlint/src-js/index.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ export function defineRule(rule: Rule): Rule {
8787
if ('create' in rule) return rule;
8888

8989
// Add `create` function to `rule`
90-
let context: Context = null, visitor: Visitor, beforeHook: BeforeHook | null;
90+
let context: Context = null,
91+
visitor: Visitor,
92+
beforeHook: BeforeHook | null;
9193

9294
rule.create = (eslintContext) => {
9395
// Lazily call `createOnce` on first invocation of `create`
@@ -155,12 +157,13 @@ function createContextAndVisitor(rule: CreateOnceRule): {
155157
if (typeof afterHook !== 'function') throw new Error('`after` property of visitor must be a function if defined');
156158

157159
const programExit = visitor['Program:exit'];
158-
visitor['Program:exit'] = programExit == null
159-
? (_node) => afterHook()
160-
: (node) => {
161-
programExit(node);
162-
afterHook();
163-
};
160+
visitor['Program:exit'] =
161+
programExit == null
162+
? (_node) => afterHook()
163+
: (node) => {
164+
programExit(node);
165+
afterHook();
166+
};
164167
}
165168

166169
return { context, visitor, beforeHook };

apps/oxlint/src-js/plugins/comments.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function getCommentsBefore(nodeOrToken: NodeOrToken): Comment[] {
4848
let sliceEnd = 0;
4949

5050
// Binary search for the comment immediately before `nodeOrToken`.
51-
for (let lo = 0, hi = commentsLength; lo < hi;) {
51+
for (let lo = 0, hi = commentsLength; lo < hi; ) {
5252
const mid = (lo + hi) >> 1;
5353
if (comments[mid].end <= targetStart) {
5454
sliceEnd = lo = mid + 1;
@@ -103,7 +103,7 @@ export function getCommentsAfter(nodeOrToken: NodeOrToken): Comment[] {
103103
let sliceEnd = 0;
104104

105105
// Binary search for the comment immediately after `nodeOrToken`.
106-
for (let lo = 0, hi = commentsLength; lo < hi;) {
106+
for (let lo = 0, hi = commentsLength; lo < hi; ) {
107107
const mid = (lo + hi) >> 1;
108108
if (comments[mid].start < targetEnd) {
109109
lo = mid + 1;
@@ -147,7 +147,7 @@ export function getCommentsInside(node: Node): Comment[] {
147147
rangeEnd = range[1];
148148

149149
// Binary search for first comment within `node`'s range.
150-
for (let lo = 0, hi = commentsLength; lo < hi;) {
150+
for (let lo = 0, hi = commentsLength; lo < hi; ) {
151151
const mid = (lo + hi) >> 1;
152152
if (comments[mid].start < rangeStart) {
153153
lo = mid + 1;
@@ -158,7 +158,7 @@ export function getCommentsInside(node: Node): Comment[] {
158158

159159
// Binary search for first comment outside `node`'s range.
160160
// Its index is used as `sliceEnd`, which is exclusive of the slice.
161-
for (let lo = sliceStart, hi = commentsLength; lo < hi;) {
161+
for (let lo = sliceStart, hi = commentsLength; lo < hi; ) {
162162
const mid = (lo + hi) >> 1;
163163
if (comments[mid].start < rangeEnd) {
164164
lo = mid + 1;
@@ -185,7 +185,7 @@ export function commentsExistBetween(nodeOrToken1: NodeOrToken, nodeOrToken2: No
185185
betweenRangeStart = nodeOrToken1.range[1];
186186
let firstCommentBetween = -1;
187187

188-
for (let lo = 0, hi = commentsLength; lo < hi;) {
188+
for (let lo = 0, hi = commentsLength; lo < hi; ) {
189189
const mid = (lo + hi) >> 1;
190190
if (comments[mid].start < betweenRangeStart) {
191191
lo = mid + 1;
@@ -194,6 +194,9 @@ export function commentsExistBetween(nodeOrToken1: NodeOrToken, nodeOrToken2: No
194194
}
195195
}
196196
// Check if it ends before `nodeOrToken2` starts.
197-
return 0 <= firstCommentBetween && firstCommentBetween < commentsLength &&
198-
comments[firstCommentBetween].end <= nodeOrToken2.range[0];
197+
return (
198+
0 <= firstCommentBetween &&
199+
firstCommentBetween < commentsLength &&
200+
comments[firstCommentBetween].end <= nodeOrToken2.range[0]
201+
);
199202
}

apps/oxlint/src-js/plugins/context.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ export const diagnostics: DiagnosticReport[] = [];
4949
* @param ruleIndex - Index of this rule within `ruleIds` passed from Rust
5050
* @param filePath - Absolute path of file being linted
5151
*/
52-
export let setupContextForFile: (
53-
context: Context,
54-
ruleIndex: number,
55-
filePath: string,
56-
) => void;
52+
export let setupContextForFile: (context: Context, ruleIndex: number, filePath: string) => void;
5753

5854
/**
5955
* Get internal data from `Context`.
@@ -138,7 +134,7 @@ export class Context {
138134
// Getter for current working directory.
139135
get cwd() {
140136
getInternal(this, 'access `context.cwd`');
141-
return cachedCwd ??= process.cwd();
137+
return (cachedCwd ??= process.cwd());
142138
}
143139

144140
// Getter for options for file being linted.
@@ -201,8 +197,12 @@ export class Context {
201197
// Do type validation checks here, to ensure no error in serialization / deserialization.
202198
// Range validation happens on Rust side.
203199
if (
204-
typeof start !== 'number' || typeof end !== 'number' ||
205-
start < 0 || end < 0 || (start | 0) !== start || (end | 0) !== end
200+
typeof start !== 'number' ||
201+
typeof end !== 'number' ||
202+
start < 0 ||
203+
end < 0 ||
204+
(start | 0) !== start ||
205+
(end | 0) !== end
206206
) {
207207
throw new TypeError('`node.range[0]` and `node.range[1]` must be non-negative integers');
208208
}
@@ -270,9 +270,9 @@ function resolveMessageFromMessageId(messageId: string, internal: InternalContex
270270

271271
if (!hasOwn(messages, messageId)) {
272272
throw new Error(
273-
`Unknown messageId '${messageId}'. Available \`messageIds\`: ${
274-
ObjectKeys(messages).map((msg) => `'${msg}'`).join(', ')
275-
}`,
273+
`Unknown messageId '${messageId}'. Available \`messageIds\`: ${ObjectKeys(messages)
274+
.map((msg) => `'${msg}'`)
275+
.join(', ')}`,
276276
);
277277
}
278278

apps/oxlint/src-js/plugins/fix.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,11 @@ function validateAndConformFix(fix: unknown): Fix {
170170
// Note: `ownKeys(fix).length === 2` rules out `fix` having a custom `toJSON` method.
171171
const fixPrototype = getPrototypeOf(fix);
172172
if (
173-
(fixPrototype === ObjectPrototype || fixPrototype === null) && ownKeys(fix).length === 2 &&
174-
getPrototypeOf(range) === ArrayPrototype && !hasOwn(range, 'toJSON') && range.length === 2 &&
173+
(fixPrototype === ObjectPrototype || fixPrototype === null) &&
174+
ownKeys(fix).length === 2 &&
175+
getPrototypeOf(range) === ArrayPrototype &&
176+
!hasOwn(range, 'toJSON') &&
177+
range.length === 2 &&
175178
typeof text === 'string'
176179
) {
177180
return fix;

apps/oxlint/src-js/plugins/location.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ export function initLines(): void {
3737
*/
3838

3939
// Note: `lineStartOffsets` starts as `[0]`
40-
let lastOffset = 0, offset, match;
40+
let lastOffset = 0,
41+
offset,
42+
match;
4143
while ((match = LINE_BREAK_PATTERN.exec(sourceText))) {
4244
offset = match.index;
4345
lines.push(sourceText.slice(lastOffset, offset));
44-
lineStartOffsets.push(lastOffset = offset + match[0].length);
46+
lineStartOffsets.push((lastOffset = offset + match[0].length));
4547
}
4648
lines.push(sourceText.slice(lastOffset));
4749
}
@@ -89,7 +91,9 @@ export function getLineColumnFromOffset(offset: number): LineColumn {
8991
*/
9092
function getLineColumnFromOffsetUnchecked(offset: number): LineColumn {
9193
// Binary search `lineStartOffsets` for the line containing `offset`
92-
let low = 0, high = lineStartOffsets.length, mid: number;
94+
let low = 0,
95+
high = lineStartOffsets.length,
96+
mid: number;
9397
do {
9498
mid = ((low + high) / 2) | 0; // Use bitwise OR to floor the division
9599
if (offset < lineStartOffsets[mid]) {

apps/oxlint/src-js/plugins/selector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function analyzeSelector(esquerySelector: EsquerySelector, selector: Selector):
144144
} else {
145145
// Selector only matches intersection of all child selectors.
146146
// TODO: Could make this faster if `analyzeSelector` always returned an ordered array.
147-
nodeTypes = childNodeTypes.filter(nodeType => nodeTypes.includes(nodeType));
147+
nodeTypes = childNodeTypes.filter((nodeType) => nodeTypes.includes(nodeType));
148148
}
149149
}
150150
return nodeTypes;

0 commit comments

Comments
 (0)