@code-pushup/eslint-plugin 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@code-pushup/eslint-plugin",
3
+ "version": "0.1.0",
4
+ "dependencies": {
5
+ "@code-pushup/utils": "*",
6
+ "eslint": "~8.46.0",
7
+ "zod": "^3.22.4",
8
+ "@code-pushup/models": "*"
9
+ },
10
+ "type": "module",
11
+ "main": "./index.js",
12
+ "types": "./src/index.d.ts"
13
+ }
package/src/bin.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/src/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { eslintPlugin } from './lib/eslint-plugin';
2
+ export default eslintPlugin;
3
+ export type { ESLintPluginConfig } from './lib/config';
@@ -0,0 +1,13 @@
1
+ import type { ESLint } from 'eslint';
2
+ import { type ZodType, z } from 'zod';
3
+ export declare const eslintPluginConfigSchema: z.ZodObject<{
4
+ eslintrc: z.ZodUnion<[z.ZodString, ZodType<ESLint.ConfigData<import("eslint").Linter.RulesRecord>, z.ZodTypeDef, ESLint.ConfigData<import("eslint").Linter.RulesRecord>>]>;
5
+ patterns: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
6
+ }, "strip", z.ZodTypeAny, {
7
+ eslintrc: (string | ESLint.ConfigData<import("eslint").Linter.RulesRecord>) & (string | ESLint.ConfigData<import("eslint").Linter.RulesRecord> | undefined);
8
+ patterns: (string | string[]) & (string | string[] | undefined);
9
+ }, {
10
+ eslintrc: (string | ESLint.ConfigData<import("eslint").Linter.RulesRecord>) & (string | ESLint.ConfigData<import("eslint").Linter.RulesRecord> | undefined);
11
+ patterns: (string | string[]) & (string | string[] | undefined);
12
+ }>;
13
+ export type ESLintPluginConfig = z.infer<typeof eslintPluginConfigSchema>;
@@ -0,0 +1,23 @@
1
+ import { PluginConfig } from '@code-pushup/models';
2
+ import { ESLintPluginConfig } from './config';
3
+ /**
4
+ * Instantiates Code PushUp ESLint plugin for use in core config.
5
+ *
6
+ * @example
7
+ * import eslintPlugin from '@code-pushup/eslint-plugin'
8
+ *
9
+ * export default {
10
+ * // ... core config ...
11
+ * plugins: [
12
+ * // ... other plugins ...
13
+ * await eslintPlugin({
14
+ * eslintrc: '.eslintrc.json',
15
+ * patterns: ['src', 'test/*.spec.js']
16
+ * })
17
+ * ]
18
+ * }
19
+ *
20
+ * @param config Configuration options.
21
+ * @returns Plugin configuration as a promise.
22
+ */
23
+ export declare function eslintPlugin(config: ESLintPluginConfig): Promise<PluginConfig>;
@@ -0,0 +1,4 @@
1
+ import type { AuditGroup } from '@code-pushup/models';
2
+ import { type RuleData } from './rules';
3
+ export declare function groupsFromRuleTypes(rules: RuleData[]): AuditGroup[];
4
+ export declare function groupsFromRuleCategories(rules: RuleData[]): AuditGroup[];
@@ -0,0 +1,2 @@
1
+ export declare function ruleIdToSlug(ruleId: string, options: unknown[] | undefined): string;
2
+ export declare function jsonHash(data: unknown, bytes?: number): string;
@@ -0,0 +1,6 @@
1
+ import type { ESLint } from 'eslint';
2
+ import type { Audit, AuditGroup } from '@code-pushup/models';
3
+ export declare function listAuditsAndGroups(eslint: ESLint, patterns: string | string[]): Promise<{
4
+ audits: Audit[];
5
+ groups: AuditGroup[];
6
+ }>;
@@ -0,0 +1,11 @@
1
+ import type { ESLint, Rule } from 'eslint';
2
+ export type RuleData = {
3
+ ruleId: string;
4
+ meta: Rule.RuleMetaData;
5
+ options: unknown[] | undefined;
6
+ };
7
+ export declare function listRules(eslint: ESLint, patterns: string | string[]): Promise<RuleData[]>;
8
+ export declare function parseRuleId(ruleId: string): {
9
+ plugin?: string;
10
+ name: string;
11
+ };
@@ -0,0 +1,3 @@
1
+ import type { Audit } from '@code-pushup/models';
2
+ import { RuleData } from './rules';
3
+ export declare function ruleToAudit({ ruleId, meta, options }: RuleData): Audit;
@@ -0,0 +1,6 @@
1
+ import type { Audit, RunnerConfig } from '@code-pushup/models';
2
+ export declare const WORKDIR: string;
3
+ export declare const RUNNER_OUTPUT_PATH: string;
4
+ export declare const ESLINTRC_PATH: string;
5
+ export declare function executeRunner(argv?: string[]): Promise<void>;
6
+ export declare function createRunnerConfig(scriptPath: string, audits: Audit[], eslintrc: string, patterns: string | string[]): RunnerConfig;
@@ -0,0 +1,3 @@
1
+ import { ESLintPluginConfig } from '../config';
2
+ import type { LinterOutput } from './types';
3
+ export declare function lint({ eslintrc, patterns, }: ESLintPluginConfig): Promise<LinterOutput>;
@@ -0,0 +1,3 @@
1
+ import type { AuditOutput } from '@code-pushup/models';
2
+ import type { LinterOutput } from './types';
3
+ export declare function lintResultsToAudits({ results, ruleOptionsPerFile, }: LinterOutput): AuditOutput[];
@@ -0,0 +1,13 @@
1
+ import type { ESLint } from 'eslint';
2
+ export type LinterOutput = {
3
+ results: LintResult[];
4
+ ruleOptionsPerFile: RuleOptionsPerFile;
5
+ };
6
+ export type LintResult = ESLint.LintResult & {
7
+ relativeFilePath: string;
8
+ };
9
+ export type RuleOptionsPerFile = {
10
+ [filePath: string]: {
11
+ [ruleId: string]: unknown[];
12
+ };
13
+ };
@@ -0,0 +1,3 @@
1
+ import { ESLint } from 'eslint';
2
+ import { ESLintPluginConfig } from './config';
3
+ export declare function setupESLint(eslintrc: ESLintPluginConfig['eslintrc']): ESLint;