Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #125 - remove debug dependency from lockfile-lint-api #127

Merged
merged 1 commit into from
Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/lockfile-lint-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Lint an npm or yarn lockfile to analyze and detect issues",
"main": "index.js",
"engines": {
"node": ">=8.0.0"
"node": ">=10.0.0"
},
"scripts": {
"lint": "eslint .",
Expand Down Expand Up @@ -49,7 +49,6 @@
},
"dependencies": {
"@yarnpkg/parsers": "^3.0.0-rc.6",
"debug": "^4.1.1",
"object-hash": "^2.0.1"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions packages/lockfile-lint-api/src/validators/ValidateHost.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict'

const {URL} = require('url')
const debug = require('debug')('lockfile-lint-api')
const {REGISTRY} = require('../common/constants')

const noop = () => {}
module.exports = class ValidateHost {
constructor ({packages} = {}) {
constructor ({packages, debug = noop} = {}) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noop here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noop by default, debug if passed.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok my bad. I missed that you have actually defined it here const noop = () => {} a few lines before :-)

if (typeof packages !== 'object') {
throw new Error('expecting an object passed to validator constructor')
}

this.packages = packages
this.debug = debug
}

validate (hosts, options) {
Expand Down Expand Up @@ -41,7 +41,7 @@ module.exports = class ValidateHost {
hostValue = parsedHost.host
}
} catch (error) {
debug(`failed parsing a URL object from given host value so using as is: ${host}`)
this.debug(`failed parsing a URL object from given host value so using as is: ${host}`)
}

return hostValue
Expand All @@ -50,7 +50,7 @@ module.exports = class ValidateHost {
const isPassing = allowedHosts.includes(packageResolvedURL.host)
if (!isPassing) {
if (!packageResolvedURL.host && options && options.emptyHostname) {
debug(`detected empty hostname but allowing because emptyHostname is not false`)
this.debug(`detected empty hostname but allowing because emptyHostname is not false`)
} else {
validationResult.errors.push({
message: `detected invalid host(s) for package: ${packageName}\n expected: ${allowedHosts}\n actual: ${
Expand Down
2 changes: 0 additions & 2 deletions packages/lockfile-lint-api/src/validators/ValidateHttps.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

const {URL} = require('url')

const HTTPS_PROTOCOL = 'https:'

module.exports = class ValidateHttps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

const {URL} = require('url')

module.exports = class ValidatePackageNames {
constructor ({packages} = {}) {
if (typeof packages !== 'object') {
Expand Down
2 changes: 0 additions & 2 deletions packages/lockfile-lint-api/src/validators/ValidateScheme.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

const {URL} = require('url')

module.exports = class ValidateProtocol {
constructor ({packages} = {}) {
if (typeof packages !== 'object') {
Expand Down
2 changes: 1 addition & 1 deletion packages/lockfile-lint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"lockfile-lint": "./bin/lockfile-lint.js"
},
"engines": {
"node": ">=8.0.0"
"node": ">=10.0.0"
},
"scripts": {
"lint": "eslint .",
Expand Down
2 changes: 1 addition & 1 deletion packages/lockfile-lint/src/validators/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function ValidateHostManager ({path, type, validatorValues, validatorOptions}) {

const parser = new ParseLockfile(options)
const lockfile = parser.parseSync()
const validator = new ValidateHost({packages: lockfile.object})
const validator = new ValidateHost({packages: lockfile.object, debug: require('debug')('lockfile-lint')})
const validationResult = validator.validate(validatorValues, validatorOptions)

// Check if some of the errors are for allowed URLs and filter those out
Expand Down