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

npm-groovy-lint

Package Overview
Dependencies
Maintainers
1
Versions
204
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npm-groovy-lint - npm Package Compare versions

Comparing version 1.2.0-beta.8 to 1.2.0-beta.10

jdeploy-bundle/groovy-lint.js

110

jdeploy-bundle/jdeploy.js
#! /usr/bin/env node
"use strict";
// Imports
const util = require("util");
const fse = require("fs-extra");
const os = require("os");
const exec = util.promisify(require("child_process").exec);
const xml2js = require("xml2js");
const NpmGroovyLint = require("./groovy-lint.js");
// Config
const jDeployRootPath = process.env.JDEPLOY_ROOT_PATH || __dirname;
const originalJdeployFile = process.env.JDEPLOY_FILE || "originaljdeploy.js";
const tempXmlFile = os.tmpdir() + "/CodeNarcReportXml_" + Math.random() + ".xml";
// Process
async function run() {
let userArgs = process.argv.slice(2);
let reformat = null;
// Remove -report userArg if existing, and add XML type
if (userArgs.includes("--ngl-console")) {
userArgs = userArgs.filter(userArg => !userArg.includes("-report=") && userArg != "--ngl-console");
userArgs.push("-report=xml:" + tempXmlFile);
reformat = "ngl-console";
}
// Build command
const jDeployCommand = '"' + process.argv[0] + '" "' + jDeployRootPath.trim() + "/" + originalJdeployFile + '" ' + userArgs.join(" ");
//console.debug(jDeployCommand);
// Run jdeploy as child process
console.info("NGL: Running CodeNarc with arguments " + userArgs.join(" "));
const { stdout, stderr } = await exec(jDeployCommand);
if (stderr && stderr !== "Picked up _JAVA_OPTIONS: -Xmx512M\n") {
console.error("NGL: Error running CodeNarc: \n" + stderr);
process.exit(1);
} else {
if (reformat == null) {
console.log("NGL: Successfully processed CodeNarc: \n" + stdout);
} else {
await reformatOutput(reformat);
}
}
process.exit(0);
}
// Reformat output if requested in command line
async function reformatOutput(reformat) {
if (reformat === "ngl-console") {
const files = await parseResult();
// Display as console log
for (const fileNm of Object.keys(files)) {
const fileErrors = files[fileNm].errors;
console.log(fileNm);
for (const err of fileErrors) {
console.log(" " + err.line.padEnd(4, " ") + " " + err.severity.padEnd(7, " ") + " " + err.rule.padEnd(24, " ") + " " + err.msg);
}
console.log("");
}
}
}
async function parseResult() {
const parser = new xml2js.Parser();
const tempXmlFileContent = await parser.parseStringPromise(fse.readFileSync(tempXmlFile), {});
if (!tempXmlFileContent || !tempXmlFileContent.CodeNarc || !tempXmlFileContent.CodeNarc.Package) {
console.log(tempXmlFileContent.CodeNarc.Package[0]);
throw new Error("Unable to parse temporary codenarc xml report file " + tempXmlFile);
}
const files = {};
for (const folderInfo of tempXmlFileContent.CodeNarc.Package) {
if (!folderInfo.File) {
continue;
}
for (const fileInfo of folderInfo.File) {
const fileNm = folderInfo["$"].path + "/" + fileInfo["$"].name;
if (files[fileNm] == null) {
files[fileNm] = { errors: [] };
}
for (const violation of fileInfo.Violation) {
const err = {
line: violation["$"].lineNumber,
rule: violation["$"].ruleName,
severity:
violation["$"].priority == "1"
? "error"
: violation["$"].priority == "2"
? "warning"
: violation["$"].priority == "3"
? "warning"
: "unknown",
msg: violation.Message ? violation.Message[0] : "NGL: No message"
};
files[fileNm].errors.push(err);
}
}
}
fse.removeSync(tempXmlFile);
return files;
}
try {
run();
} catch (e) {
console.error("NGL: Error :( \n" + e.message);
process.exit(99);
}
const linter = new NpmGroovyLint({}, process.argv);
linter.run();
{
"name": "npm-groovy-lint",
"version": "1.2.0-beta.8",
"version": "1.2.0-beta.10",
"description": "NPM CodeNarc wrapper to easily lint Groovy files",

@@ -12,8 +12,9 @@ "main": "index.js",

"postbuild": "node patch-jdeploy-after.js",
"test:codenarc": "npm run build && npm-groovy-lint -basedir=\"jdeploy-bundle\" -rulesetfiles=\"file:jdeploy-bundle/lib/example/RuleSet-Base.groovy\" -title=\"TestTitle\" -maxPriority1Violations=0 -report=\"html:jdeploy-bundle/lib/example/ReportTestCodeNarc.html\" --ngl-console",
"test:js": "SET JDEPLOY_ROOT_PATH=jdeploy-bundle && node src/index.js -basedir=\"jdeploy-bundle/lib/example\" -rulesetfiles=\"file:jdeploy-bundle/lib/example/RuleSet-Base.groovy\" -title=\"TestTitle\" -maxPriority1Violations=0 -report=\"html:jdeploy-bundle/lib/example/ReportTestJs.html\" --ngl-console",
"test:js:debug": "SET JDEPLOY_ROOT_PATH=jdeploy-bundle && node --inspect-brk src/index.js -basedir=\"jdeploy-bundle/lib/example\" -rulesetfiles=\"file:jdeploy-bundle/lib/example/RuleSet-Base.groovy\" -title=\"TestTitle\" -maxPriority1Violations=0 -report=\"html:jdeploy-bundle/lib/example/ReportTestJsDbg.html\" --ngl-console",
"test": "npm run test:codenarc && npm run test:js",
"publish-to-npm": "npm run build && npm publish",
"publish-beta-to-npm": "npm run build && npm publish --tag beta"
"test:codenarc": "npm run build && npm-groovy-lint -basedir=\"jdeploy-bundle\" -rulesetfiles=\"file:jdeploy-bundle/lib/example/RuleSet-Base.groovy\" -title=\"TestTitle\" -maxPriority1Violations=0 -report=\"html:jdeploy-bundle/lib/example/ReportTestCodeNarc.html\" --ngl-output=json",
"pretest": "npm run build",
"test": "mocha \"test/**/*.test.js\"",
"test:coverage": "nyc npm run test",
"test:debug": "mocha --reporter spec --inspect-brk \"test/**/*.test.js\"",
"publish:release": "npm run build && npm publish",
"publish:beta": "npm run build && npm publish --tag beta"
},

@@ -45,2 +46,3 @@ "repository": {

"fs-extra": "^8.1.0",
"glob": "^7.1.6",
"shelljs": "^0.7.5",

@@ -50,2 +52,3 @@ "xml2js": "^0.4.23"

"devDependencies": {
"babel-eslint": "^10.0.3",
"eslint": "^6.8.0",

@@ -59,5 +62,9 @@ "eslint-config-standard": "^14.1.0",

"mocha": "^7.0.1",
"nyc": "^15.0.0-beta.3",
"prettier": "1.19.1",
"rimraf": "^3.0.2"
},
"engines": {
"node": ">=8.0.0"
},
"jdeploy": {

@@ -75,3 +82,26 @@ "jar": "dist/lib/CodeNarc-1.4.jar",

"jdeploy-bundle"
]
],
"mocha": {
"require": [
"test/helpers/init.js"
],
"watch-extensions": [
"js"
],
"recursive": true,
"reporter": "spec",
"timeout": "300000"
},
"nyc": {
"include": [
"src/**"
],
"extension": [
".js"
],
"reporter": [
"html"
],
"all": true
}
}

@@ -5,2 +5,4 @@ # NPM GROOVY LINT

[![Downloads/week](https://img.shields.io/npm/dw/npm-groovy-lint.svg)](https://npmjs.org/package/npm-groovy-lint)
[![CircleCI](https://circleci.com/gh/nvuillam/npm-groovy-lint/tree/master.svg?style=shield)](https://circleci.com/gh/nvuillam/npm-groovy-lint/tree/master)
[![codecov](https://codecov.io/gh/nvuillam/npm-groovy-lint/branch/master/graph/badge.svg)](https://codecov.io/gh/nvuillam/npm-groovy-lint)
[![GitHub contributors](https://img.shields.io/github/contributors/nvuillam/npm-groovy-lint.svg)](https://gitHub.com/nvuillam/npm-groovy-lint/graphs/contributors/)

@@ -36,2 +38,26 @@ [![GitHub stars](https://img.shields.io/github/stars/nvuillam/npm-groovy-lint?style=social&label=Star&maxAge=2592000)](https://GitHub.com/nvuillam/npm-groovy-lint/stargazers/)

```
## npm-groovy-lint OPTIONS
| Parameter | Description | Example |
|--------------|--------------------------------------------------------------------------------------------------------------|-------------------------------------|
| --ngl-output=format | npm-groovy-lint provided output (reformatted from CodeNarc output).<br/> Available formats: <br/>- text (default)<br/> - json | --ngl-output=json <br/> --ngl-output=text |
| | | |
## CodeNarc OPTIONS
| Parameter | Description | Example |
|--------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| -basedir=DIR | The base (root) directory for the source code to be analyzed. Defaults to the current directory ("."). | -basedir=src/main/groovy |
| -includes=PATTERNS | The comma-separated list of Ant-style file patterns specifying files that must be included. Defaults to "**/*.groovy". | -includes=**/*.gr |
| -excludes=PATTERNS | The comma-separated list of Ant-style file patterns specifying files that must be excluded. No files are excluded when omitted. | -excludes=**/templates/**, **/*Test.* |
| -rulesetfiles=FILENAMES | The path to the Groovy or XML RuleSet definition files. This can be a single file path, or multiple paths separated by commas. By default, the paths specified are relative to the classpath. But these paths may be optionally prefixed by any of the valid java.net.URL prefixes, such as "file:" (to load from a relative or absolute path on the filesystem), or "http:". If it is a URL, its path may be optionally URL-encoded. That can be useful if the path contains any problematic characters, such as comma (',') or hash ('#'). For instance: "file:src/test/resources/RuleSet-,#.txt" can be encoded as: "file:src%2Ftest%2Fresources%2FRuleSet-%2C%23.txt" See URLEncoder#encode(java.lang.String, java.lang.String). Defaults to "rulesets/basic.xml". | -rulesetfiles=rulesets/imports.xml, rulesets/naming.xml |
| -report=REPORT-TYPE[:FILENAME] | The definition of the report to produce. The option value is of the form TYPE[:FILENAME], where TYPE is one of the predefined type names: "html", "xml", "text", "console" or else the fully-qualified class name of a class (accessible on the classpath) that implements the org.codenarc.report.ReportWriter interface. And FILENAME is the filename (with optional path) of the output report filename. If the report filename is omitted, the default filename for the report type is used ("CodeNarcReport.html" for "html" and "CodeNarcXmlReport.xml" for "xml"). If no report option is specified, default to a single "html" report with the default filename. | -report=html -report=html:MyProject.html -report=xml -report=xml:MyXmlReport.xml -report=org.codenarc.report. HtmlReportWriter |
| -maxPriority1Violations=MAX | The maximum number of priority 1 violations allowed (int). | -maxPriority1Violations=0 |
| -maxPriority2Violations=MAX | The maximum number of priority 2 violations allowed (int). | -maxPriority2Violations=0 |
| -maxPriority3Violations=MAX | The maximum number of priority 3 violations allowed (int). | -maxPriority3Violations=0 |
| -title=REPORT TITLE | The title for this analysis; used in the output report(s), if supported by the report type(s). Optional. | -title="My Project" |
| -help | Display the command-line help. If present, this must be the only command-line parameter. | -help |
See OPTIONS in [CodeNarc documentation](http://codenarc.sourceforge.net/codenarc-command-line.html)

@@ -42,6 +68,19 @@

```
$ npm-groovy-lint -report="xml:MyGroovyLinterReport.xml"
// npm-groovy-lint output
$ npm-groovy-lint -report="xml:MyGroovyLinterReport.xml" --ngl-format=text
// npm-groovy-lint output
$ npm-groovy-lint -includes=**/Jenkinsfile -rulesetfiles="file:config/codenarc/RuleSet-Base.groovy" --ngl-format=json
// CodeNarc output
$ npm-groovy-lint -includes=**/Jenkinsfile -rulesetfiles="file:config/codenarc/RuleSet-All.groovy" -title="MyJenkinsfileLinterReport" -maxPriority1Violations=0 -report="html:MyJenkinsfileLinterReport.html"
// CodeNarc output
$ npm-groovy-lint -basedir="src" -rulesetfiles="file:config/codenarc/RuleSet-Base.groovy" -title="MyGroovyLinterReport" -maxPriority1Violations=0 -report="html:MyGroovyLinterReport.html"

@@ -55,3 +94,3 @@ ```

- Fork the repo and clone it on your computer
- Run `npm run test` to check your updates (jdeploy.js is manually updated by `npm run prepare-package` script)
- Run `npm run lint` then `npm run test` to check your updates
- Once your code is ready, documented and linted, please make a pull request :)

@@ -58,0 +97,0 @@

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