Skip to content

Commit

Permalink
Update dependency @ota-meshi/eslint-plugin to ^0.12.0 (#140)
Browse files Browse the repository at this point in the history
* Update dependency @ota-meshi/eslint-plugin to ^0.12.0

* format

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Yosuke Ota <[email protected]>
  • Loading branch information
renovate[bot] and ota-meshi authored Aug 31, 2022
1 parent 7b630e9 commit 64354d5
Show file tree
Hide file tree
Showing 30 changed files with 3,177 additions and 3,218 deletions.
108 changes: 54 additions & 54 deletions benchmark/index.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
// eslint-disable-next-line eslint-comments/disable-enable-pair -- ignore
/* eslint-disable require-jsdoc, no-console -- ignore */
import * as Benchmark from "benchmark"
import fs from "fs"
import { parseForESLint } from ".."
import { parseForESLint as parseOld } from "../node_modules/jsonc-eslint-parser"
import * as Benchmark from "benchmark";
import fs from "fs";
import { parseForESLint } from "..";
import { parseForESLint as parseOld } from "../node_modules/jsonc-eslint-parser";

const contents = `${fs.readFileSync(
require.resolve("../package.json"),
"utf-8",
)}// comments`
require.resolve("../package.json"),
"utf-8"
)}// comments`;

type Result = { name: string; hz: number }
const results: Result[] = []
type Result = { name: string; hz: number };
const results: Result[] = [];

function format(hz: number): string {
return (~~(hz * 100) / 100).toString().padEnd(4, " ").padStart(6, " ")
return (~~(hz * 100) / 100).toString().padEnd(4, " ").padStart(6, " ");
}

function onCycle(event: { target: Result }): void {
const { name, hz } = event.target
results.push({ name, hz })
const { name, hz } = event.target;
results.push({ name, hz });

console.log(event.target.toString())
console.log(event.target.toString());
}

function onComplete(): void {
console.log("-".repeat(72))
const map: Record<string, number[]> = {}
for (const result of results) {
const r = (map[result.name.slice(2)] ??= [])
r.push(result.hz)
}
for (const name of Object.keys(map)) {
console.log(
`${name.padEnd(15)} ${format(
map[name].reduce((p, a) => p + a, 0) / map[name].length,
)} ops/sec`,
)
}
for (let i = 0; i < results.length; ++i) {
const result = results[i]
console.log("-".repeat(72));
const map: Record<string, number[]> = {};
for (const result of results) {
const r = (map[result.name.slice(2)] ??= []);
r.push(result.hz);
}
for (const name of Object.keys(map)) {
console.log(
`${name.padEnd(15)} ${format(
map[name].reduce((p, a) => p + a, 0) / map[name].length
)} ops/sec`
);
}
for (let i = 0; i < results.length; ++i) {
const result = results[i];

console.log(`${result.name.padEnd(15)} ${format(result.hz)} ops/sec`)
}
console.log(`${result.name.padEnd(15)} ${format(result.hz)} ops/sec`);
}
}

const suite = new Benchmark.Suite("benchmark", { onCycle, onComplete })
const suite = new Benchmark.Suite("benchmark", { onCycle, onComplete });

for (const no of [1, 2, 3]) {
suite.add(`${no} new jsonc-eslint-parser`, function () {
parseForESLint(contents, {
loc: true,
range: true,
raw: true,
tokens: true,
comment: true,
eslintVisitorKeys: true,
eslintScopeManager: true,
})
})
suite.add(`${no} old jsonc-eslint-parser`, function () {
parseOld(contents, {
loc: true,
range: true,
raw: true,
tokens: true,
comment: true,
eslintVisitorKeys: true,
eslintScopeManager: true,
})
})
suite.add(`${no} new jsonc-eslint-parser`, function () {
parseForESLint(contents, {
loc: true,
range: true,
raw: true,
tokens: true,
comment: true,
eslintVisitorKeys: true,
eslintScopeManager: true,
});
});
suite.add(`${no} old jsonc-eslint-parser`, function () {
parseOld(contents, {
loc: true,
range: true,
raw: true,
tokens: true,
comment: true,
eslintVisitorKeys: true,
eslintScopeManager: true,
});
});
}

suite.run()
suite.run();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"homepage": "https://github.com/ota-meshi/jsonc-eslint-parser#readme",
"devDependencies": {
"@ota-meshi/eslint-plugin": "^0.11.0",
"@ota-meshi/eslint-plugin": "^0.12.0",
"@types/benchmark": "^2.1.0",
"@types/eslint": "^8.0.0",
"@types/eslint-visitor-keys": "^1.0.0",
Expand Down
44 changes: 22 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import { parseForESLint } from "./parser/parser"
import { traverseNodes } from "./parser/traverse"
import { parseForESLint } from "./parser/parser";
import { traverseNodes } from "./parser/traverse";
import {
getStaticJSONValue,
isExpression,
isNumberIdentifier,
isUndefinedIdentifier,
} from "./utils/ast"
getStaticJSONValue,
isExpression,
isNumberIdentifier,
isUndefinedIdentifier,
} from "./utils/ast";

import type * as AST from "./parser/ast"
import { getVisitorKeys } from "./parser/visitor-keys"
import type * as AST from "./parser/ast";
import { getVisitorKeys } from "./parser/visitor-keys";

// parser
export { parseForESLint }
export { parseForESLint };
// Keys
// eslint-disable-next-line @typescript-eslint/naming-convention -- parser module
export const VisitorKeys = getVisitorKeys()
export const VisitorKeys = getVisitorKeys();

// tools
export {
traverseNodes,
getStaticJSONValue,
isExpression,
isNumberIdentifier,
isUndefinedIdentifier,
}
traverseNodes,
getStaticJSONValue,
isExpression,
isNumberIdentifier,
isUndefinedIdentifier,
};

/**
* Parse JSON source code
*/
export function parseJSON(
code: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- any
options?: any,
code: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- any
options?: any
): AST.JSONProgram {
return parseForESLint(code, options).ast as never
return parseForESLint(code, options).ast as never;
}

// types
export { AST }
export { AST };
Loading

0 comments on commit 64354d5

Please sign in to comment.