Skip to content

Commit 9e31454

Browse files
committed
chore: clean up and update devDependencies
1 parent 5741fd9 commit 9e31454

File tree

97 files changed

+1699
-1975
lines changed

Some content is hidden

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

97 files changed

+1699
-1975
lines changed

.mocharc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"extension": ["ts"],
3-
"node-option": ["loader=ts-node/esm", "no-warnings"]
3+
"node-option": ["experimental-transform-types"]
44
}

benchmark/benchmark.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import fs from "node:fs";
1+
import { readdirSync, readFileSync } from "node:fs";
22
import path from "node:path";
33
import { bench, do_not_optimize, run } from "mitata";
44
import prettier from "prettier";
55
import javaPlugin from "../dist/index.mjs";
66

77
const dir = "samples";
8-
const files = fs
9-
.readdirSync(dir, { recursive: true })
8+
const files = readdirSync(dir, { recursive: true })
109
.filter(file => file.endsWith(".java"))
1110
.map(file => path.join(dir, file), "utf8");
1211

1312
bench("prettier-plugin-java", async () => {
1413
try {
1514
for (const file of files) {
16-
const out = await prettier.format(fs.readFileSync(file, "utf-8"), {
15+
const out = await prettier.format(readFileSync(file, "utf-8"), {
1716
parser: "java",
1817
plugins: [javaPlugin]
1918
});

eslint.config.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import js from "@eslint/js";
1+
import eslint from "@eslint/js";
2+
import { defineConfig } from "eslint/config";
23
import globals from "globals";
34
import tseslint from "typescript-eslint";
4-
import { defineConfig } from "eslint/config";
55

6-
export default defineConfig([
6+
export default defineConfig(
77
{
8-
files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
9-
plugins: { js },
10-
extends: ["js/recommended"],
11-
languageOptions: { globals: { ...globals.browser, ...globals.node } }
8+
languageOptions: {
9+
globals: globals.node
10+
}
1211
},
12+
eslint.configs.recommended,
1313
tseslint.configs.recommended
14-
]);
14+
);

package.json

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"postinstall": "cp node_modules/tree-sitter-java-orchard/tree-sitter-java_orchard.wasm src/ && node scripts/generate-node-types.ts && prettier --write src/node-types.ts",
3333
"lerna:publish": "lerna publish from-git --yes",
3434
"lerna:version": "lerna version --exact --no-private",
35-
"lint": "eslint src/**/*.ts",
35+
"lint": "eslint src test",
3636
"prepare": "husky",
3737
"test": "yarn run test:unit && yarn run test:e2e-core",
3838
"test:all": "yarn run test && yarn run test:e2e-jhipster1 && yarn run test:e2e-jhipster2",
@@ -57,27 +57,21 @@
5757
},
5858
"devDependencies": {
5959
"@eslint/js": "^10.0.1",
60-
"@types/chai": "^5.0.1",
61-
"@types/emscripten": "^1.41.5",
62-
"@types/fs-extra": "^11.0.4",
63-
"@types/klaw-sync": "^6.0.5",
60+
"@types/chai": "^5.2.3",
6461
"@types/mocha": "^10.0.10",
65-
"@types/node": "^18.19.64",
66-
"chai": "^5.1.2",
67-
"eslint": "^10.0.3",
68-
"fs-extra": "^11.2.0",
62+
"@types/node": "^25.5.0",
63+
"chai": "^6.2.2",
64+
"eslint": "^10.1.0",
6965
"globals": "^17.4.0",
70-
"husky": "^9.1.6",
71-
"klaw-sync": "^6.0.0",
72-
"lerna": "^8.1.9",
73-
"lint-staged": "^15.2.10",
66+
"husky": "^9.1.7",
67+
"lerna": "^9.0.7",
68+
"lint-staged": "^16.4.0",
7469
"mitata": "^1.0.34",
75-
"mocha": "^10.8.2",
76-
"prettier": "^3.0.0",
77-
"ts-node": "^10.9.2",
70+
"mocha": "^11.7.5",
71+
"prettier": "^3.8.1",
7872
"tsdown": "^0.21.4",
79-
"typescript": "^5.6.3",
80-
"typescript-eslint": "^8.57.0"
73+
"typescript": "^5.9.3",
74+
"typescript-eslint": "^8.57.1"
8175
},
8276
"peerDependencies": {
8377
"prettier": "^3.0.0"

scripts/clone-samples.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
/* eslint-disable no-console */
2-
import cp from "child_process";
3-
import path from "path";
4-
import fs from "fs-extra";
5-
import url from "url";
1+
import { execSync } from "node:child_process";
2+
import { mkdirSync, rmSync } from "node:fs";
3+
import path from "node:path";
4+
import { fileURLToPath } from "node:url";
65

7-
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
6+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
87
const samplesDir = path.resolve(__dirname, "../samples");
98

109
const core = [
@@ -86,23 +85,24 @@ if (process.argv.length === 3) {
8685
}
8786
}
8887

89-
fs.emptyDirSync(samplesDir);
88+
rmSync(samplesDir, { force: true, recursive: true });
89+
mkdirSync(samplesDir);
9090

9191
sampleRepos.forEach(cloneRepo);
9292

9393
function cloneRepo({ repoUrl, branch, commitHash }) {
9494
console.log(`cloning ${repoUrl}`);
9595
if (commitHash) {
96-
cp.execSync(`git clone ${repoUrl} --branch ${branch}`, {
96+
execSync(`git clone ${repoUrl} --branch ${branch}`, {
9797
cwd: samplesDir,
9898
stdio: [0, 1, 2]
9999
});
100-
cp.execSync(`git checkout ${commitHash}`, {
100+
execSync(`git checkout ${commitHash}`, {
101101
cwd: path.resolve(samplesDir, repoUrl.split("/").pop()),
102102
stdio: [0, 1, 2]
103103
});
104104
} else {
105-
cp.execSync(`git clone ${repoUrl} --branch ${branch} --depth 1`, {
105+
execSync(`git clone ${repoUrl} --branch ${branch} --depth 1`, {
106106
cwd: samplesDir,
107107
stdio: [0, 1, 2]
108108
});

scripts/generate-node-types.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import fs from "node:fs";
1+
import { writeFileSync } from "node:fs";
22
import nodeTypeInfo from "tree-sitter-java-orchard/src/node-types.json" with { type: "json" };
33

4-
fs.writeFileSync(
4+
writeFileSync(
55
"src/node-types.ts",
66
`interface Point {
77
index: number;
@@ -30,7 +30,7 @@ export interface UnnamedNode<T extends UnnamedType = UnnamedType> extends Syntax
3030
}
3131
3232
export interface CommentNode extends SyntaxNodeBase {
33-
type: SyntaxType.BlockComment | SyntaxType.LineComment;
33+
type: CommentType;
3434
leading: boolean;
3535
trailing: boolean;
3636
printed: boolean;
@@ -54,7 +54,9 @@ ${nodeTypeInfo
5454
.join("\n")}
5555
};
5656
57-
export type NamedType = Exclude<SyntaxType, SyntaxType.BlockComment | SyntaxType.LineComment>;
57+
export type CommentType = SyntaxType.BlockComment | SyntaxType.LineComment;
58+
59+
export type NamedType = Exclude<SyntaxType, CommentType>;
5860
5961
export type UnnamedType = ${nodeTypeInfo
6062
.filter(({ named }) => !named)

scripts/update-test-output.js

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1-
/* eslint-disable no-console */
2-
import klawSync from "klaw-sync";
3-
import path from "path";
4-
import fs from "fs-extra";
1+
import {
2+
cpSync,
3+
existsSync,
4+
readdirSync,
5+
readFileSync,
6+
rmSync,
7+
writeFileSync
8+
} from "node:fs";
9+
import path from "node:path";
10+
import { fileURLToPath } from "node:url";
511
import prettier from "prettier";
6-
import url from "url";
712

8-
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
13+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
914

1015
const updateTestOutput = async () => {
1116
let samplesDir = path.resolve(__dirname, "../test/unit-test");
12-
let originalSamplesDir = samplesDir;
1317
if (process.argv.indexOf("-single") > -1) {
1418
samplesDir = path.resolve(__dirname, "./single-printer-run");
1519
} else if (process.argv.indexOf("-repository") > -1) {
1620
const testSamples = path.resolve(__dirname, "../test-samples");
17-
originalSamplesDir = path.resolve(
21+
const originalSamplesDir = path.resolve(
1822
__dirname,
1923
process.argv[process.argv.indexOf("-repository") + 1]
2024
);
2125
samplesDir = path.resolve(testSamples, path.basename(originalSamplesDir));
22-
if (fs.existsSync(samplesDir)) {
23-
fs.removeSync(samplesDir);
26+
if (existsSync(samplesDir)) {
27+
rmSync(samplesDir, { recursive: true });
2428
}
2529
console.log(`start copy ${originalSamplesDir} to ${samplesDir}`);
26-
fs.copySync(originalSamplesDir, samplesDir);
30+
cpSync(originalSamplesDir, samplesDir);
2731
console.log(`end copy ${originalSamplesDir} to ${samplesDir}`);
2832
}
2933

@@ -32,30 +36,35 @@ const updateTestOutput = async () => {
3236
numberOfTime = process.argv[process.argv.indexOf("-times") + 1];
3337
}
3438

35-
const sampleFiles = klawSync(samplesDir, { nodir: true });
36-
const javaSampleFiles = sampleFiles.filter(fileDesc => {
37-
if (fileDesc.path.includes("node_modules")) {
38-
return false;
39-
}
40-
if (process.argv.indexOf("-repository") > -1) {
41-
return fileDesc.path.endsWith(".java");
42-
}
43-
return fileDesc.path.endsWith("input.java");
39+
const sampleFiles = readdirSync(samplesDir, {
40+
encoding: "utf-8",
41+
recursive: true
4442
});
43+
const javaSampleFiles = sampleFiles
44+
.filter(filePath => {
45+
if (filePath.includes("node_modules")) {
46+
return false;
47+
}
48+
if (process.argv.indexOf("-repository") > -1) {
49+
return filePath.endsWith(".java");
50+
}
51+
return filePath.endsWith("input.java");
52+
})
53+
.map(filePath => path.join(samplesDir, filePath));
4554

4655
let failures = 0;
4756
await Promise.all(
48-
javaSampleFiles.map(async fileDesc => {
49-
const javaFileText = fs.readFileSync(fileDesc.path, "utf8");
57+
javaSampleFiles.map(async filePath => {
58+
const javaFileText = readFileSync(filePath, "utf8");
5059

5160
try {
52-
console.log(`Reading <${fileDesc.path}>`);
61+
console.log(`Reading <${filePath}>`);
5362
let newExpectedText = javaFileText;
5463

55-
const testDir = path.dirname(fileDesc.path);
64+
const testDir = path.dirname(filePath);
5665
const optionsPath = path.join(testDir, ".prettierrc.json");
57-
const testOptions = fs.existsSync(optionsPath)
58-
? fs.readJsonSync(optionsPath)
66+
const testOptions = existsSync(optionsPath)
67+
? JSON.parse(readFileSync(optionsPath, "utf-8"))
5968
: {};
6069

6170
for (let i = 0; i < numberOfTime; i++) {
@@ -78,18 +87,15 @@ const updateTestOutput = async () => {
7887
...testOptions
7988
});
8089
}
81-
let outputFilePath = fileDesc.path.replace(
82-
/input.java$/,
83-
"output.java"
84-
);
90+
let outputFilePath = filePath.replace(/input.java$/, "output.java");
8591
if (process.argv.indexOf("-repository") > -1) {
86-
outputFilePath = fileDesc.path;
92+
outputFilePath = filePath;
8793
}
8894
console.log(`writing <${outputFilePath}>`);
89-
fs.writeFileSync(outputFilePath, newExpectedText);
95+
writeFileSync(outputFilePath, newExpectedText);
9096
} catch (e) {
9197
failures++;
92-
console.log(`Failed parsing: <${fileDesc.path}>`);
98+
console.log(`Failed parsing: <${filePath}>`);
9399
console.log(e);
94100
}
95101
})

src/comments.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { util, type AstPath, type Doc } from "prettier";
22
import { builders } from "prettier/doc";
3-
import { SyntaxType, type CommentNode, type SyntaxNode } from "./node-types.js";
4-
import parser from "./parser.js";
5-
import printer from "./printer.js";
3+
import { SyntaxType, type CommentNode, type SyntaxNode } from "./node-types.ts";
4+
import parser from "./parser.ts";
5+
import printer from "./printer.ts";
66
import {
77
hasChild,
88
printComment,
99
type JavaParserOptions,
1010
type NamedNodePath
11-
} from "./printers/helpers.js";
11+
} from "./printers/helpers.ts";
1212

1313
const { hasNewline, isPreviousLineEmpty, skipNewline, skipSpaces } = util;
1414
const { breakParent, hardline, line, lineSuffix } = builders;

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { Plugin } from "prettier";
2-
import type { SyntaxNode } from "./node-types.js";
3-
import options from "./options.js";
4-
import parser from "./parser.js";
5-
import printer from "./printer.js";
2+
import type { SyntaxNode } from "./node-types.ts";
3+
import options from "./options.ts";
4+
import parser from "./parser.ts";
5+
import printer from "./printer.ts";
66

77
export default {
88
languages: [

src/node-types.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface UnnamedNode<
2727
}
2828

2929
export interface CommentNode extends SyntaxNodeBase {
30-
type: SyntaxType.BlockComment | SyntaxType.LineComment;
30+
type: CommentType;
3131
leading: boolean;
3232
trailing: boolean;
3333
printed: boolean;
@@ -196,10 +196,9 @@ export const enum SyntaxType {
196196
VoidType = "void_type"
197197
}
198198

199-
export type NamedType = Exclude<
200-
SyntaxType,
201-
SyntaxType.BlockComment | SyntaxType.LineComment
202-
>;
199+
export type CommentType = SyntaxType.BlockComment | SyntaxType.LineComment;
200+
201+
export type NamedType = Exclude<SyntaxType, CommentType>;
203202

204203
export type UnnamedType =
205204
| "!"

0 commit comments

Comments
 (0)