npm-package-json-lint
Version:
Configurable linter for package.json files.
270 lines • 6.79 kB
TypeScript
import { PackageJson } from "type-fest";
//#region src/types/severity.d.ts
declare enum Severity {
Error = "error",
Warning = "warning",
Off = "off"
}
//#endregion
//#region src/lint-issue.d.ts
/**
* A lint issue
*/
declare class LintIssue {
/**
* Unique, lowercase, hyphen-separate name for the lint
*
* @type {string}
* @memberof LintIssue
*/
lintId: string;
/**
* 'error' or 'warning'
*
* @type {Severity}
* @memberof LintIssue
*/
severity: Severity;
/**
* Name of the node in the JSON the lint audits
*
* @type {string}
* @memberof LintIssue
*/
node: string;
/**
* Human-friendly message to users
*
* @type {string}
* @memberof LintIssue
*/
lintMessage: string;
/**
* Creates an instance of LintIssue.
* @param lintId Unique, lowercase, hyphen-separate name for the lint
* @param severity 'error' or 'warning'
* @param node Name of the node in the JSON the lint audits
* @param lintMessage Human-friendly message to users
* @memberof LintIssue
*/
constructor(lintId: string, severity: Severity, node: string, lintMessage: string);
/**
* Helper to convert the LintIssue to a printable string
*
* @returns {string} Human-friendly message about the lint issue
*/
toString(): string;
}
//#endregion
//#region src/types/lint-result.d.ts
type LintResult = LintIssue | null;
//#endregion
//#region src/types/lint-function.d.ts
type StandardLintFunction = (packageJsonData: PackageJson | any, severity: Severity) => LintResult;
type ArrayLintFunction = <T>(packageJsonData: PackageJson | any, severity: Severity, ruleConfig: T[]) => LintResult;
type ObjectLintFunction = (packageJsonData: PackageJson | any, severity: Severity, ruleConfig: Record<string, boolean>) => LintResult;
interface OptionalObjectRuleConfig {
exceptions?: string[];
}
type OptionalObjectLintFunction = (packageJsonData: PackageJson | any, severity: Severity, ruleConfig: OptionalObjectRuleConfig) => LintResult;
type LintFunction = StandardLintFunction | ArrayLintFunction | ObjectLintFunction | OptionalObjectLintFunction;
//#endregion
//#region src/types/rule-type.d.ts
declare enum RuleType {
Array = "array",
Object = "object",
OptionalObject = "optionalObject",
Standard = "standard"
}
//#endregion
//#region src/native-rules.d.ts
interface Rule {
lint: LintFunction;
ruleType: RuleType;
minItems?: number;
}
declare class Rules {
rules: Record<string, string>;
constructor();
/**
* Loads rules
*
* @return Set of rules
*/
load(): Record<string, string>;
/**
* Loads a rule module
*
* @param ruleId Name of the rule
* @return Rule module
*/
get(ruleId: string): Rule;
/**
* Gets entire rule set
*
* @returns Rule set
*/
getRules(): Record<string, string>;
/**
* Registers a rule in the rules object
*
* @param ruleId Name of the rule
* @param filePathToRuleModule File path to rule
*/
registerRule(ruleId: string, filePathToRuleModule: string): void;
}
//#endregion
//#region src/configuration.d.ts
/**
* Config class
* @class
*/
declare class Config {
/**
* The user passed config object.
*/
config: any;
/**
* The current working directory.
*/
cwd: string;
/**
* The user passed configFile path.
*/
configFile: any;
/**
* The base directory that config should be pulled from.
*/
configBaseDirectory: any;
/**
* Rules object
*/
rules: any;
constructor(cwd: string, config: any, configFile: any, configBaseDirectory: any, rules: Rules);
/**
* Gets the config for a file.
*
* @param filePath File path of the file being linted.
* @returns {Object} A config object.
* @memberof Config
*/
getConfigForFile(filePath: string): any;
}
//#endregion
//#region src/types/package-json-linting-result.d.ts
interface PackageJsonFileLintingResult {
/**
* File path to the package.json file
*/
filePath: string;
/**
* A list of issues.
*/
issues: LintIssue[];
/**
* A flag indicating that the file was skipped.
*/
ignored: boolean;
/**
* Number of errors.
*/
errorCount: number;
/**
* Number of warnings.
*/
warningCount: number;
}
//#endregion
//#region src/linter/results-helper.d.ts
/**
* A result count object for a files.
* @typedef {Object} FileResultCounts
* @property {number} errorCount Number of errors for a file result.
* @property {number} warningCount Number of warnings for a file result.
*/
interface PackageJsonFileAggregatedResultCounts {
errorCount: number;
warningCount: number;
}
interface OverallAggregatedResultCounts {
/**
* Total number of ignored files.
*/
ignoreCount: number;
/**
* Total number of errors.
*/
errorCount: number;
/**
* Total number of warnings.
*/
warningCount: number;
}
//#endregion
//#region src/linter/linter.d.ts
interface LinterResult {
results: LintIssue[];
ignoreCount: number;
/**
* Number of errors for the package.json file.
*/
errorCount: number;
/**
* Number of warnings for the package.json file.
*/
warningCount: number;
}
interface OverallLintingResult extends OverallAggregatedResultCounts {
results: PackageJsonFileLintingResult[];
}
//#endregion
//#region src/npm-package-json-lint.d.ts
interface NpmPackageJsonLintOptions {
cwd?: string;
packageJsonObject?: any;
packageJsonFilePath?: string;
config?: any;
configFile?: any;
configBaseDirectory?: any;
patterns?: any;
quiet?: boolean;
ignorePath?: string;
fix?: boolean;
}
declare class NpmPackageJsonLint {
cwd: string;
packageJsonObject: any;
packageJsonFilePath: string;
patterns: any;
quiet: boolean;
ignorePath: string;
fix: boolean;
version: string;
rules: Rules;
configHelper: Config;
/**
* constructor
* @param options An instance of the {@link NpmPackageJsonLintOptions} options object.
* @constructor
*/
constructor(options: NpmPackageJsonLintOptions);
/**
* Runs the linter using the config specified in the constructor
*
* @returns The results {@link OverallLintingResult} from linting a collection of package.json files.
*/
lint(): OverallLintingResult;
}
//#endregion
//#region src/console-reporter.d.ts
/**
* Print results to console
*
* @param linterOutput An array of LintIssues
* @param quiet Flag indicating whether to print warnings.
* @internal
*/
declare const write: (linterOutput: any, quiet: boolean) => void;
//#endregion
export { LintIssue, type LinterResult, NpmPackageJsonLint, type NpmPackageJsonLintOptions, type OverallAggregatedResultCounts, type PackageJsonFileAggregatedResultCounts, type PackageJsonFileLintingResult, type Rule, Rules, Severity, write };
//# sourceMappingURL=api.d.ts.map