11const debug = require ( 'debug' ) ( 'npm-package-json-lint:linter' ) ;
22import path from 'path' ;
33import { Parser } from '../Parser' ;
4- import { resultsHelper } from './results-helper' ;
4+ import { RuleType } from '../types/rule-type' ;
5+ import { Severity } from '../types/severity' ;
6+ import { aggregateCountsPerFile , aggregateOverallCounts } from './results-helper' ;
57
68/**
79 * A package.json file linting result.
@@ -48,13 +50,13 @@ const lint = (packageJsonData, configObj, rules) => {
4850 for ( const rule in configObj ) {
4951 const ruleModule = rules . get ( rule ) ;
5052
51- let severity = 'off' ;
53+ let severity = Severity . Off ;
5254 let ruleConfig = { } ;
5355
54- if ( ruleModule . ruleType === 'array' || ruleModule . ruleType === 'object' ) {
56+ if ( ruleModule . ruleType === RuleType . Array || ruleModule . ruleType === RuleType . Object ) {
5557 severity = typeof configObj [ rule ] === 'string' && configObj [ rule ] === 'off' ? configObj [ rule ] : configObj [ rule ] [ 0 ] ;
5658 ruleConfig = typeof configObj [ rule ] === 'string' ? { } : configObj [ rule ] [ 1 ] ;
57- } else if ( ruleModule . ruleType === 'optionalObject' ) {
59+ } else if ( ruleModule . ruleType === RuleType . OptionalObject ) {
5860 if ( typeof configObj [ rule ] === 'string' ) {
5961 severity = configObj [ rule ] ;
6062 ruleConfig = { } ;
@@ -66,7 +68,7 @@ const lint = (packageJsonData, configObj, rules) => {
6668 severity = configObj [ rule ] ;
6769 }
6870
69- if ( severity !== 'off' ) {
71+ if ( severity !== Severity . Off ) {
7072 const lintResult = ruleModule . lint ( packageJsonData , severity , ruleConfig ) ;
7173
7274 if ( typeof lintResult === 'object' ) {
@@ -91,7 +93,7 @@ const lint = (packageJsonData, configObj, rules) => {
9193 */
9294const processPackageJsonObject = ( cwd , packageJsonObj , config , fileName , rules ) => {
9395 const lintIssues = lint ( packageJsonObj , config , rules ) ;
94- const counts = resultsHelper . aggregateCountsPerFile ( lintIssues ) ;
96+ const counts = aggregateCountsPerFile ( lintIssues ) ;
9597 const result = createResultObject ( {
9698 cwd,
9799 fileName,
@@ -140,7 +142,7 @@ const processPackageJsonFile = (cwd, fileName, config, rules) => {
140142 * @param {Object } rules An instance of `Rules`.
141143 * @returns {LinterResult } The results {@link LinterResult} from linting a collection of package.json files.
142144 */
143- export const executeOnPackageJsonObject = ( { cwd, packageJsonObject, filename, ignorer, configHelper, rules} ) => {
145+ export const executeOnPackageJsonObject = ( { cwd, packageJsonObject, filename, ignorer, configHelper, rules} ) : any => {
144146 debug ( 'executing on package.json object' ) ;
145147 const results = [ ] ;
146148
@@ -172,7 +174,7 @@ export const executeOnPackageJsonObject = ({cwd, packageJsonObject, filename, ig
172174 }
173175
174176 debug ( 'Aggregating overall counts' ) ;
175- const stats = resultsHelper . aggregateOverallCounts ( results ) ;
177+ const stats = aggregateOverallCounts ( results ) ;
176178
177179 debug ( 'stats' ) ;
178180 debug ( stats ) ;
@@ -194,7 +196,7 @@ export const executeOnPackageJsonObject = ({cwd, packageJsonObject, filename, ig
194196 * @param {Object } rules An instance of `Rules`.
195197 * @returns {LinterResult } The results {@link LinterResult} from linting a collection of package.json files.
196198 */
197- export const executeOnPackageJsonFiles = ( { cwd, fileList, ignorer, configHelper, rules} ) => {
199+ export const executeOnPackageJsonFiles = ( { cwd, fileList, ignorer, configHelper, rules} ) : any => {
198200 debug ( 'executing on package.json files' ) ;
199201 const results = fileList . map ( ( filePath ) => {
200202 const relativeFilePath = path . relative ( cwd , filePath ) ;
@@ -221,7 +223,7 @@ export const executeOnPackageJsonFiles = ({cwd, fileList, ignorer, configHelper,
221223 } ) ;
222224
223225 debug ( 'Aggregating overall counts' ) ;
224- const stats = resultsHelper . aggregateOverallCounts ( results ) ;
226+ const stats = aggregateOverallCounts ( results ) ;
225227
226228 debug ( 'stats' ) ;
227229 debug ( stats ) ;
0 commit comments