Comparing version 1.0.1 to 2.0.0
@@ -14,18 +14,118 @@ #!/usr/bin/env node | ||
var polylint = require('../polylint'); | ||
var jsconf_policy = require('../lib/jsconf-policy'); | ||
var colors = require('colors/safe'); | ||
var cliArgs = require("command-line-args"); | ||
var fs = require('fs'); | ||
var root, path; | ||
if (process.argv.length > 3) { | ||
root = process.argv[2]; | ||
path = process.argv[3]; | ||
} else { | ||
root = process.cwd(); | ||
path = process.argv[2]; | ||
var cli = cliArgs([ | ||
{ | ||
name: "help", | ||
type: Boolean, | ||
alias: "h", | ||
description: "Print usage." | ||
}, | ||
{ | ||
name: "verbose", | ||
type: Boolean, | ||
alias: "v", | ||
description: "Writes verbose logging." | ||
}, | ||
{ | ||
name: "debug", | ||
type: Boolean, | ||
alias: "g", | ||
description: "Writes debugging trace." | ||
}, | ||
{ | ||
name: "policy", | ||
type: String, | ||
alias: "p", | ||
description: "Your jsconf.json policy file.", | ||
defaultValue: null | ||
}, | ||
{ | ||
name: "root", | ||
type: String, | ||
defaultValue: '', | ||
description: ( | ||
"Root directory against which URLs in inputs are resolved." | ||
+ " If not specified, then the current working directory is used." | ||
) | ||
}, | ||
{ | ||
name: "input", | ||
type: String, | ||
alias: "i", | ||
defaultOption: true, | ||
multiple: true, | ||
description: ( | ||
"Polymer source files." | ||
+ " If a directory is specified, it is used as the root" | ||
+ " for resolving relative URLs in the next input." | ||
) | ||
} | ||
]); | ||
var usage = cli.getUsage({ | ||
header: "polylint checks Polymer apps for problematic code patterns", | ||
title: "polylint" | ||
}); | ||
var options = cli.parse(); | ||
if (options.help) { | ||
console.log(usage); | ||
process.exit(0); | ||
} | ||
if (!path) { | ||
console.error("Usage: polylint [workdir] <filename>"); | ||
process.exit(1); | ||
// Check options and dump usage if we find problems. | ||
var inputsOk = true; | ||
var inputs = options.input; | ||
var policyPath = options.policy; | ||
if (!inputs.length) { | ||
console.error('Missing input polymer path'); | ||
inputsOk = false; | ||
} | ||
if (!inputsOk) { | ||
console.log(usage); | ||
process.exit(-1); | ||
} | ||
var jsconfPolicyPromise = Promise.resolve(null); | ||
if (options.policy) { | ||
jsconfPolicyPromise = new Promise(function (fulfill, reject) { | ||
fs.readFile( | ||
options.policy, | ||
{ encoding: 'utf8' }, | ||
function (err, fileContent) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
try { | ||
fulfill(jsconf_policy.fromRequirements(JSON.parse(fileContent))); | ||
} catch (ex) { | ||
reject(ex); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
var root = options.root || ''; | ||
// Make sure resolution has a path segment to drop. | ||
// According to URL rules, | ||
// resolving index.html relative to /foo/ produces /foo/index.html, but | ||
// resolving index.html relative to /foo produces /index.html | ||
// is different from resolving index.html relative to /foo/ | ||
// This removes any ambiguity between URL resolution rules and file path | ||
// resolution which might lead to confusion. | ||
if (root !== '' && !/[\/\\]$/.test(root)) { | ||
root += '/'; | ||
} | ||
function prettyPrintWarning(warning) { | ||
@@ -38,8 +138,37 @@ var warning = colors.red(warning.filename) + ":" + | ||
polylint(path, {root: root}).then(function(lintWarnings){ | ||
lintWarnings.forEach(function(warning){ | ||
prettyPrintWarning(warning); | ||
}) | ||
}).catch(function(err){ | ||
console.log(err.stack); | ||
}); | ||
// Pair inputs with root directories so that for the command line | ||
// polylint.js foo/ foo/foo.html bar.html other/ main.html | ||
// we kick off three analyses: | ||
// 1. root='foo/' path='foo.html' | ||
// 2. root='', path='bar.html' | ||
// 3. root='other/', path='main.html' | ||
(function processInput(inputIndex) { | ||
if (inputIndex === inputs.length) { | ||
// We're done. | ||
return; // TODO: exit with a signal indicating whether errors occurred. | ||
} | ||
// Check whether input is a root directory before picking a root and | ||
// a path to process. | ||
var input = inputs[inputIndex]; | ||
// Finally invoke the analyzer. | ||
polylint( | ||
input, | ||
{ | ||
root: root, | ||
jsconfPolicy: jsconfPolicyPromise | ||
}) | ||
.then(function(lintWarnings){ | ||
lintWarnings.forEach(function(warning){ | ||
prettyPrintWarning(warning); | ||
}); | ||
// Process any remaining inputs. | ||
processInput(inputIndex + 1); | ||
}) | ||
.catch(function(err){ | ||
console.error(err.stack); | ||
}); | ||
}(0)); |
{ | ||
"name": "polylint", | ||
"private": true, | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/PolymerLabs/polylint", | ||
@@ -6,0 +6,0 @@ "authors": [ |
{ | ||
"name": "polylint", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Keeps your Polymer Elements clean and functional!", | ||
@@ -22,4 +22,5 @@ "main": "polylint.js", | ||
"colors": "^1.1.0", | ||
"command-line-args": "^1.0.0", | ||
"dom5": "^1.0.2", | ||
"hydrolysis": "^1.5.0", | ||
"hydrolysis": "^1.15.4", | ||
"optimist": "^0.6.1", | ||
@@ -26,0 +27,0 @@ "pegjs": "^0.8.0", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
77152
29
1775
1
13
7
2
+ Addedcommand-line-args@^1.0.0
+ Addedansi-escape-sequences@2.2.2(transitive)
+ Addedarray-back@1.0.4(transitive)
+ Addedarray-tools@2.0.9(transitive)
+ Addedcollect-all@0.2.11.0.4(transitive)
+ Addedcollect-json@1.0.9(transitive)
+ Addedcolumn-layout@1.3.02.1.4(transitive)
+ Addedcommand-line-args@1.0.22.1.6(transitive)
+ Addedcommand-line-usage@1.2.12.0.5(transitive)
+ Addeddeep-extend@0.4.2(transitive)
+ Addedfeature-detect-es6@1.5.0(transitive)
+ Addedfilter-where@1.0.1(transitive)
+ Addedfind-replace@1.0.3(transitive)
+ Addedobject-get@2.1.1(transitive)
+ Addedobject-tools@2.0.6(transitive)
+ Addedreduce-extract@1.0.0(transitive)
+ Addedreduce-flatten@1.0.1(transitive)
+ Addedreduce-unique@1.0.0(transitive)
+ Addedreduce-without@1.0.1(transitive)
+ Addedsort-array@1.1.2(transitive)
+ Addedstream-connect@1.0.2(transitive)
+ Addedstream-via@0.1.11.0.4(transitive)
+ Addedtest-value@1.1.02.1.0(transitive)
+ Addedtypical@2.6.1(transitive)
+ Addedwordwrapjs@1.2.1(transitive)
Updatedhydrolysis@^1.15.4