Skip to content

Commit 70c558e

Browse files
authored
feat: export meta object (#234)
1 parent 6784ea5 commit 70c558e

17 files changed

+111
-23
lines changed

.changeset/brown-doors-crash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-jsonc": minor
3+
---
4+
5+
feat: export meta object

lib/configs/prettier.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// IMPORTANT!
2+
// This file has been automatically generated,
3+
// in order to update its content execute "npm run update"
14
import path from "path";
25
const base = require.resolve("./base");
36
const baseExtend =

lib/configs/recommended-with-json.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// IMPORTANT!
2+
// This file has been automatically generated,
3+
// in order to update its content execute "npm run update"
14
import path from "path";
25
const base = require.resolve("./base");
36
const baseExtend =

lib/configs/recommended-with-json5.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// IMPORTANT!
2+
// This file has been automatically generated,
3+
// in order to update its content execute "npm run update"
14
import path from "path";
25
const base = require.resolve("./base");
36
const baseExtend =

lib/configs/recommended-with-jsonc.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// IMPORTANT!
2+
// This file has been automatically generated,
3+
// in order to update its content execute "npm run update"
14
import path from "path";
25
const base = require.resolve("./base");
36
const baseExtend =

lib/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import recommendedWithJsonc from "./configs/recommended-with-jsonc";
77
import recommendedWithJson5 from "./configs/recommended-with-json5";
88
import prettier from "./configs/prettier";
99
import all from "./configs/all";
10+
import * as meta from "./meta";
1011

1112
// backward compatibility
1213
import {
@@ -33,6 +34,7 @@ const rules = ruleList.reduce((obj, r) => {
3334
}, {} as { [key: string]: RuleModule });
3435

3536
export default {
37+
meta,
3638
configs,
3739
rules,
3840
// as parser
@@ -43,6 +45,7 @@ export default {
4345
getStaticJSONValue,
4446
};
4547
export {
48+
meta,
4649
configs,
4750
rules,
4851
// as parser

lib/meta.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// IMPORTANT!
2+
// This file has been automatically generated,
3+
// in order to update its content execute "npm run update"
4+
export const name = "eslint-plugin-jsonc" as const;
5+
export const version = "2.7.0" as const;

lib/utils/rules.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// IMPORTANT!
2+
// This file has been automatically generated,
3+
// in order to update its content execute "npm run update"
14
import type { RuleModule } from "../types";
25
import arrayBracketNewline from "../rules/array-bracket-newline";
36
import arrayBracketSpacing from "../rules/array-bracket-spacing";

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
},
1818
"scripts": {
1919
"prebuild": "npm run -s clean",
20-
"build": "npm run build:ts && npm run build:dts",
20+
"build": "npm run build:meta && npm run build:ts && npm run build:dts",
21+
"build:meta": "ts-node --transpile-only ./tools/update-meta.ts",
2122
"build:ts": "tsc --project ./tsconfig.build.json",
2223
"build:dts": "npm run build:dts-step1 && npm run build:dts-step2",
2324
"build:dts-step1": "tsc --declaration --outDir dist-ts --project ./tsconfig.build.json",

tests/lib/meta.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import assert from "assert";
2+
import plugin from "../../lib";
3+
import { version } from "../../package.json";
4+
const expectedMeta = {
5+
name: "eslint-plugin-jsonc",
6+
version,
7+
};
8+
9+
describe("Test for meta object", () => {
10+
it("A plugin should have a meta object.", () => {
11+
assert.strictEqual(plugin.meta.name, expectedMeta.name);
12+
assert.strictEqual(typeof plugin.meta.version, "string");
13+
});
14+
15+
for (const [name, processor] of Object.entries(
16+
// @ts-expect-error -- missing processors
17+
plugin.processors || {}
18+
)) {
19+
it(`"${name}" processor should have a meta object.`, () => {
20+
// @ts-expect-error -- missing type
21+
assert.strictEqual(processor.meta.name, expectedMeta.name);
22+
// @ts-expect-error -- missing type
23+
assert.strictEqual(typeof processor.meta.version, "string");
24+
});
25+
}
26+
});

0 commit comments

Comments
 (0)