11import isPlainObj from 'is-plain-obj' ;
22import slash from 'slash' ;
3+ import { PackageJson } from 'type-fest' ;
34import { Config } from './Config' ;
4- import { Rules } from './Rules ' ;
5- import { executeOnPackageJsonFiles , executeOnPackageJsonObject } from './linter/linter' ;
5+ import { Rules } from './rules ' ;
6+ import { executeOnPackageJsonFiles , executeOnPackageJsonObject , OverallLintingResult } from './linter/linter' ;
67import { getFileList } from './utils/getFileList' ;
78import { getIgnorer } from './utils/getIgnorer' ;
89import { Severity } from './types/severity' ;
10+ import { PackageJsonFileLintingResult } from './types/package-json-linting-result' ;
11+ import { LintIssue } from './lint-issue' ;
912
1013// eslint-disable-next-line @typescript-eslint/no-var-requires
1114const debug = require ( 'debug' ) ( 'npm-package-json-lint:NpmPackageJsonLint' ) ;
@@ -17,29 +20,27 @@ const noIssues = 0;
1720/**
1821 * Checks if the given issue is an error issue.
1922 *
20- * @param { LintIssue } issue npm-package-json-lint issue
21- * @returns { boolean } True if error, false if warning.
23+ * @param issue A { @link LintIssue} object
24+ * @returns True if error, false if warning.
2225 * @private
2326 */
24- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
25- const isIssueAnError = ( issue ) => issue . severity === Severity . Error ;
27+ const isIssueAnError = ( issue : LintIssue ) : boolean => issue . severity === Severity . Error ;
2628
27- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
28- const isPackageJsonObjectValid = ( packageJsonObject ) => isPlainObj ( packageJsonObject ) ;
29+ // eslint-disable-next-line @typescript-eslint/no- explicit-any
30+ const isPackageJsonObjectValid = ( packageJsonObject : PackageJson | any ) : boolean => isPlainObj ( packageJsonObject ) ;
2931
30- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
31- const areRequiredOptionsValid = ( packageJsonObject , patterns ) =>
32+ // eslint-disable-next-line @typescript-eslint/no- explicit-any
33+ const areRequiredOptionsValid = ( packageJsonObject : PackageJson | any , patterns : string [ ] ) : boolean =>
3234 ( ! patterns && ! isPackageJsonObjectValid ( packageJsonObject ) ) ||
3335 ( patterns && ( packageJsonObject || isPackageJsonObjectValid ( packageJsonObject ) ) ) ;
3436
3537/**
3638 * Filters results to only include errors.
3739 *
38- * @param { LintResult[] } results The results to filter.
39- * @returns { LintResult[] } The filtered results.
40+ * @param results The results to filter.
41+ * @returns The filtered results.
4042 */
41- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
42- const getErrorResults = ( results ) => {
43+ const getErrorResults = ( results : PackageJsonFileLintingResult [ ] ) : PackageJsonFileLintingResult [ ] => {
4344 const filtered = [ ] ;
4445
4546 results . forEach ( ( result ) => {
@@ -60,16 +61,6 @@ const getErrorResults = (results) => {
6061 return filtered ;
6162} ;
6263
63- /**
64- * CLIEngine configuration object
65- *
66- * @typedef {Object } NpmPackageJsonLint
67- * @property {string } configFile The configuration file to use.
68- * @property {string } cwd The value to use for the current working directory.
69- * @property {boolean } useConfigFiles False disables use of .npmpackagejsonlintrc.json files, npmpackagejsonlint.config.js files, and npmPackageJsonLintConfig object in package.json file.
70- * @property {Object<string,*> } rules An object of rules to use.
71- */
72-
7364export interface NpmPackageJsonLintOptions {
7465 cwd ?: string ;
7566 // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -88,10 +79,6 @@ export interface NpmPackageJsonLintOptions {
8879 fix ?: boolean ;
8980}
9081
91- /**
92- * Public CLIEngine class
93- * @class
94- */
9582export class NpmPackageJsonLint {
9683 cwd : string ;
9784
@@ -117,7 +104,7 @@ export class NpmPackageJsonLint {
117104
118105 /**
119106 * constructor
120- * @param { NpmPackageJsonLint } options The options for the CLIEngine .
107+ * @param options An instance of the { @link NpmPackageJsonLintOptions} options object .
121108 * @constructor
122109 */
123110 constructor ( options : NpmPackageJsonLintOptions ) {
@@ -154,11 +141,9 @@ export class NpmPackageJsonLint {
154141 /**
155142 * Runs the linter using the config specified in the constructor
156143 *
157- * @returns {LinterResult } The results {@link LinterResult} from linting a collection of package.json files.
158- * @memberof NpmPackageJsonLint
144+ * @returns The results {@link OverallLintingResult} from linting a collection of package.json files.
159145 */
160- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
161- lint ( ) {
146+ lint ( ) : OverallLintingResult {
162147 debug ( 'Starting lint' ) ;
163148
164149 if ( areRequiredOptionsValid ( this . packageJsonObject , this . patterns ) ) {
@@ -168,7 +153,7 @@ export class NpmPackageJsonLint {
168153 }
169154
170155 const ignorer = getIgnorer ( this . cwd , this . ignorePath ) ;
171- let linterOutput ;
156+ let linterOutput : OverallLintingResult ;
172157
173158 if ( this . patterns ) {
174159 debug ( 'Linting using patterns' ) ;
0 commit comments