Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

polylint

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polylint - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

lib/jsconf-policy.js

163

bin/polylint.js

@@ -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));

2

bower.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc