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 3.2.0 to 3.2.1-beta.1

jdeploy-bundle/lib/example/.groovylintrc-customname.json

58

CHANGELOG.md
# Changelog
## [3.2.1] 2020-03-29
- Return rules descriptions in results
- Fixes
- [Issue #13](https://github.com/nvuillam/npm-groovy-lint/issues/13): False positive error ClassNameSameAsFileName
- Sometimes returning wrong .groovylint.json config file
## [3.2.0] 2020-03-26
### Added
- New option "--format", allowing to reformat source code (using .groovylintrc-format.json)
### Changed
- Update default recommended rules

@@ -15,4 +17,2 @@

### Changed
- README: Link to [Visual Studio Code Groovy Lint extension](https://marketplace.visualstudio.com/items?itemName=NicolasVuillamy.vscode-groovy-lint)

@@ -22,5 +22,3 @@

### Added
- Fix rules:
- New Fix rules:
- BlockEndsWithBlankLine

@@ -30,5 +28,2 @@ - BlockStartsWithBlankLine

- SpaceAfterIf
### Changed
- Fix: Update correctly the lineNb & ranges of next errors after an error has been fixed

@@ -44,5 +39,3 @@ - Do not return rules tests if call is not from a test file

### Added
- Fix rules:
- New Fix rules:
- BlockEndsWithBlankLine

@@ -52,6 +45,3 @@ - BlockStartsWithBlankLine

- SpaceAfterIf
### Changed
- Fix rules:
- Updated Fix rules:
- SpaceAroundOperator

@@ -61,7 +51,5 @@

### Changed
- Test suites: Improve reliability & logs for rule fixes tests (detected numerous bugs, now corrected)
- Send computed range to fix functions
- Fix rules:
- Updated Fix rules:
- ClosingBraceNotAlone

@@ -79,8 +67,3 @@ - ElseBlockBraces

### Added
- Add new test suites: errors.test.js and miscellaneous.test.js
### Changed
- Use JSON as default GroovyLint configuration file type

@@ -96,4 +79,2 @@ - Order of fixable rules must be defined in groovy-lint-rules.js

### Added
- Local microservice "CodeNarcServer" called via Http by npm-groovy-lint, to avoid loading all groovy/java classes at each lint request. This microservice autokills itself after one hour idle.

@@ -105,5 +86,2 @@ - Capability to define RuleSets in argument or js/json/yml config file formats instead of groovy/xml RuleSet format

- Generate automatically .groovylintrc-all.js during build
## Changed
- Split rules definition into files instead of all in a huge single file

@@ -119,4 +97,2 @@ - Reorganise groovy-lint.js code, using codenarc-factory.js and codenarc-caller.js

### Added
- Capability to call NpmGroovyLint with options as object, not only command line arguments

@@ -132,4 +108,2 @@ - New option "source", allowing to call NpmGroovyLint with the groovy code as a string , not only path & files pattern

### Added
- Capability to fix errors

@@ -155,6 +129,3 @@ - ConsecutiveBlankLines

- More code coverage with test campaigns
- Capability to call NpmGrooyLint from another package (VsCode extension development in progress ^^)
### Changed
- New Capability to call NpmGrooyLint from another package (VsCode extension development in progress ^^)
- Refactored command line arguments ( simpler, but different from CodeNarc ones : retro-compatibility with CodeNarc arguments assured if you add --codenarcargs)

@@ -164,7 +135,2 @@ - Upgrade to CodeNarc v1.5

- Refactored documentation with detailed arguments description & examples
# Removed
- CodeNarc original format of command line arguments
___

@@ -171,0 +137,0 @@ ## Before

@@ -60,4 +60,7 @@ // Call CodeNarc by server or java

try {
const startCodeNarc = performance.now();
parsedBody = await rp(rqstOptions);
this.serverStatus = "running";
const elapsed = parseInt(performance.now() - startCodeNarc, 10);
debug(`CodeNarc runned in ${elapsed} ms`);
} catch (e) {

@@ -64,0 +67,0 @@ // If server not started , start it and try again

@@ -7,2 +7,3 @@ // Shared functions

const os = require("os");
const path = require("path");
const xml2js = require("xml2js");

@@ -17,2 +18,3 @@ const { getNpmGroovyLintRules } = require("./groovy-lint-rules.js");

const npmGroovyLintRules = getNpmGroovyLintRules();
const CODENARC_TMP_FILENAME_BASE = "codeNarcTmpFile_";

@@ -29,6 +31,19 @@ // Convert NPM-groovy-lint into codeNarc arguments

if (options.source) {
cnPath = os.tmpdir();
const tmpFileNm = "codeNarcTmpFile_" + Math.random() + ".groovy";
result.tmpGroovyFileName = os.tmpdir() + "/" + tmpFileNm;
cnFiles = "**/" + tmpFileNm;
cnPath = path.resolve(os.tmpdir() + "/npm-groovy-lint");
await fse.ensureDir(cnPath);
// File path is sent (recommended): use it to create temp file name
if (options.sourcefilepath) {
const pathParse = path.parse(options.sourcefilepath);
cnPath = cnPath + "/codeNarcTmpDir_" + Math.random();
await fse.ensureDir(cnPath);
result.tmpGroovyFileName = path.resolve(cnPath + "/" + pathParse.base);
cnFiles = "**/" + pathParse.base;
}
// Use default random file name
else {
const tmpFileNm = CODENARC_TMP_FILENAME_BASE + Math.random() + ".groovy";
result.tmpGroovyFileName = path.resolve(cnPath + "/" + tmpFileNm);
cnFiles = "**/" + tmpFileNm;
}
await fse.writeFile(result.tmpGroovyFileName, options.source);

@@ -41,2 +56,3 @@ debug(`CREATE GROOVY temp file ${result.tmpGroovyFileName} with input source, as CodeNarc requires physical files`);

result.codeNarcBaseDir = cnPath !== "." ? baseBefore + cnPath.replace(/^"(.*)"$/, "$1") : process.cwd();
result.codeNarcBaseDir = path.resolve(result.codeNarcBaseDir);
result.codenarcArgs.push('-basedir="' + result.codeNarcBaseDir + '"');

@@ -69,3 +85,4 @@

result.outputType = result.output.endsWith(".txt") ? "txt" : result.output.endsWith(".json") ? "json" : result.output;
result.tmpXmlFileName = os.tmpdir() + "/codeNarcReportXml_" + Math.random() + ".xml";
await fse.ensureDir(os.tmpdir() + "/npm-groovy-lint");
result.tmpXmlFileName = path.resolve(os.tmpdir() + "/npm-groovy-lint/codeNarcReportXml_" + Math.random() + ".xml");
result.codenarcArgs.push('-report=xml:"' + result.tmpXmlFileName + '"');

@@ -116,2 +133,5 @@ } else if (["html", "xml"].includes(result.output.split(".").pop())) {

const tmpGroovyFileNameReplace =
tmpGroovyFileName && tmpGroovyFileName.includes(CODENARC_TMP_FILENAME_BASE) ? path.parse(tmpGroovyFileName).base : null;
// Parse files & violations

@@ -149,3 +169,3 @@ const files = {};

};
errItem.msg = tmpGroovyFileName ? errItem.msg.replace(tmpGroovyFileName, "") : errItem.msg;
errItem.msg = tmpGroovyFileNameReplace ? errItem.msg.replace(tmpGroovyFileNameReplace, "") : errItem.msg;
// Find range & add error only if severity is matching logLevel

@@ -180,5 +200,13 @@ if (

}
// Complete with files with no error
result.files = files;
result.files = files;
// Parse error definitions if not already done
if (result.rules == null) {
const rules = {};
for (const ruleDef of tempXmlFileContent.CodeNarc.Rules[0].Rule) {
rules[ruleDef["$"].name] = { description: ruleDef.Description[0] };
}
result.rules = rules;
}
return result;

@@ -242,3 +270,4 @@ }

// Write file
const tmpRuleSetFileName = os.tmpdir() + "/codeNarcTmpRs_" + Math.random() + ".groovy";
await fse.ensureDir(path.resolve(os.tmpdir() + "/npm-groovy-lint"));
const tmpRuleSetFileName = path.resolve(os.tmpdir() + "/npm-groovy-lint/codeNarcTmpRs_" + Math.random() + ".groovy");
await fse.writeFile(tmpRuleSetFileName, ruleSetSource);

@@ -245,0 +274,0 @@ debug(`CREATE RULESET tmp file ${tmpRuleSetFileName} generated from input options, as CodeNarc requires physical files`);

@@ -27,3 +27,3 @@ // Configuration file management

// Load configuration from identified file, or find config file from a start path
async function loadConfig(startPathOrFile, mode = "lint", fileNames = []) {
async function loadConfig(startPathOrFile, mode = "lint", sourcefilepath, fileNames = []) {
let defaultConfig = defaultConfigLintFileName;

@@ -36,3 +36,3 @@ if (mode === "lint" && fileNames.length === 0) {

}
const configFilePath = await getConfigFileName(startPathOrFile, fileNames, defaultConfig);
const configFilePath = await getConfigFileName(startPathOrFile, sourcefilepath, fileNames, defaultConfig);
// Load user configuration from file

@@ -69,8 +69,16 @@ let configUser = await loadConfigFromFile(configFilePath);

// Returns configuration filename
async function getConfigFileName(startPathOrFile, fileNames = configLintFilenames, defaultConfig = defaultConfigLintFileName) {
async function getConfigFileName(startPathOrFile, sourcefilepath, fileNames = configLintFilenames, defaultConfig = defaultConfigLintFileName) {
let configFilePath = null;
const stat = await fse.lstat(startPathOrFile);
// Find one of the config file formats are the root of the linted file (if source is sent with sourcefilepath)
if ([".", process.cwd()].includes(startPathOrFile) && sourcefilepath) {
const stat = await fse.lstat(sourcefilepath);
const dir = stat.isDirectory() ? sourcefilepath : path.parse(sourcefilepath).dir;
configFilePath = await findConfigInPath(dir, fileNames);
}
// Find one of the config file formats at the root of the project or at upper directory levels
if (stat.isDirectory()) {
configFilePath = await findConfigInPath(startPathOrFile, fileNames);
if (configFilePath == null) {
const stat = await fse.lstat(startPathOrFile);
const dir = stat.isDirectory ? startPathOrFile : path.parse(startPathOrFile).dir;
configFilePath = await findConfigInPath(dir, fileNames);
}

@@ -81,2 +89,4 @@ if (configFilePath == null) {

}
configFilePath = path.resolve(configFilePath);
debug(`GroovyLint used config file: ${configFilePath}`);
return configFilePath;

@@ -133,3 +143,2 @@ }

async function loadJSConfigFile(filePath) {
debug(`Loading JS config file: ${filePath}`);
try {

@@ -146,3 +155,2 @@ return importFresh(filePath);

async function loadJSONConfigFile(filePath) {
debug(`Loading JSON config file: ${filePath}`);
try {

@@ -165,4 +173,2 @@ const fileContent = await readFile(filePath);

async function loadYAMLConfigFile(filePath) {
debug(`Loading YAML config file: ${filePath}`);
// lazy load YAML to improve performance when not used

@@ -184,3 +190,2 @@ const yaml = require("js-yaml");

async function loadPackageJSONConfigFile(filePath) {
debug(`Loading package.json config file: ${filePath}`);
try {

@@ -187,0 +192,0 @@ const packageData = await loadJSONConfigFile(filePath);

@@ -97,3 +97,3 @@ #! /usr/bin/env node

async getConfigFilePath(path) {
return getConfigFileName(path || this.options.config);
return getConfigFileName(path || this.options.path || this.options.config, "lint", this.options.sourcefilepath);
}

@@ -115,3 +115,7 @@

this.options = optionsDefinition.parse(this.args);
const configProperties = await loadConfig(this.options.config, this.options.format ? "format" : "lint");
const configProperties = await loadConfig(
this.options.config || this.options.path,
this.options.format ? "format" : "lint",
this.options.sourcefilepath
);
for (const configProp of Object.keys(configProperties)) {

@@ -118,0 +122,0 @@ if (this.options[configProp] == null) {

@@ -32,3 +32,3 @@ /**

description: "Directory containing the files to lint (default: current directory)",
example: "./path/to/my/groovy/files"
example: ["./path/to/my/groovy/files"]
},

@@ -50,2 +50,9 @@ {

{
option: "sourcefilepath",
type: "String",
dependsOn: ["source"],
description: "",
example: ["C:/some/folder/myScript.groovy", "/var/some/folder/myScript.groovy"]
},
{
option: "config",

@@ -56,4 +63,4 @@ alias: "c",

description:
"Custom path to GroovyLint config file.\n Default: Found groovylintrc.js/json/yml/package.json config file, or default npm-groovy-lint config if not defined. \nNote: command-line arguments have priority on config file properties",
example: ["./config/.groovylintrc-custom.js", "./config/.groovylintrc-custom.json"]
"Custom path to directory containing GroovyLint config file.\n Default: Found groovylintrc.js/json/yml/package.json config file, or default npm-groovy-lint config if not defined. \nNote: command-line arguments have priority on config file properties",
example: ["./config", "./config/whatever"]
},

@@ -76,3 +83,4 @@ {

dependsOn: ["fix"],
description: "List of rule identifiers to fix (if not specified, all available fixes will be applied)"
description: "List of rule identifiers to fix (if not specified, all available fixes will be applied)",
example: ["SpaceBeforeClosingBrace,SpaceAfterClosingBrace,UnusedImport"]
},

@@ -134,6 +142,7 @@ {

type: "Boolean",
example:
'npm-groovy-lint --codenarcargs -basedir="jdeploy-bundle/lib/example" -rulesetfiles="file:jdeploy-bundle/lib/example/RuleSet-Groovy.groovy" -maxPriority1Violations=0 -report="xml:ReportTestCodenarc.xml',
description:
"Use core CodeNarc arguments (all npm-groovy-lint arguments will be ignored). Doc: http://codenarc.github.io/CodeNarc/codenarc-command-line.html"
"Use core CodeNarc arguments (all npm-groovy-lint arguments will be ignored). Doc: http://codenarc.github.io/CodeNarc/codenarc-command-line.html",
example: [
'npm-groovy-lint --codenarcargs -basedir="jdeploy-bundle/lib/example" -rulesetfiles="file:jdeploy-bundle/lib/example/RuleSet-Groovy.groovy" -maxPriority1Violations=0 -report="xml:ReportTestCodenarc.xml'
]
},

@@ -156,3 +165,4 @@ {

default: "7484",
description: "If use of CodeNarc server, port of the CodeNarc server (default: 7484)"
description: "If use of CodeNarc server, port of the CodeNarc server (default: 7484)",
example: ["2702"]
},

@@ -179,3 +189,2 @@ {

["files", "source", "codenarcargs", "help", "version"],
[["path", "files"], "source"],
["failonerror", "failonwarning", "failoninfo"],

@@ -182,0 +191,0 @@ ["codenarcargs", ["failonerror", "failonwarning", "failoninfo", "path", "files", "source", "fix", "fixrules", "config"]],

{
"name": "npm-groovy-lint",
"version": "3.2.0",
"version": "3.2.1-beta.1",
"description": "NPM CodeNarc wrapper to easily lint Groovy files",

@@ -19,3 +19,3 @@ "main": "index.js",

"publish:beta": "npm run build && npm publish --tag beta",
"dev:lint-build-all": "npm run lint:fix && npm run groovy:build && npm run build",
"dev:lint-build-all": "npm run lint:fix && npm run build",
"dev:test-in-vscode-groovy-lint": "npm run dev:lint-build-all && node script-deploy-in-vscode.js"

@@ -22,0 +22,0 @@ },

@@ -11,5 +11,3 @@ # NPM GROOVY LINT (and FIX !)

[![License](https://img.shields.io/npm/l/npm-groovy-lint.svg)](https://github.com/nvuillam/npm-groovy-lint/blob/master/package.json)
[![HitCount](https://hits.dwyl.com/nvuillam/npm-groovy-lint.svg)](https://hits.dwyl.com/nvuillam/npm-groovy-lint)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![Say Thanks!](https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg)](https://saythanks.io/to/nicolas.vuillamy@gmail.com)

@@ -67,9 +65,9 @@ **Groovy / Jenkinsfile linter and autofixer**

Define a file named **.groovylintrc.js** (or .json or .YAML, or include in a property groovyLintConfig in package.json)
Define a file named **.groovylintrc.json** (or .js or .YAML, or include in a property groovyLintConfig in package.json)
Format :
- extends: Name of a base configuration ([`recommended`](https://github.com/nvuillam/npm-groovy-lint/blob/master/.groovylintrc-recommended.js) or [`all`](https://github.com/nvuillam/npm-groovy-lint/blob/master/.groovylintrc-all.js))
- extends: Name of a base configuration ([`recommended`](https://github.com/nvuillam/npm-groovy-lint/blob/master/.groovylintrc-recommended.json) or [`all`](https://github.com/nvuillam/npm-groovy-lint/blob/master/.groovylintrc-all.json))
- rules: List of rules definition, following format `"RuleSection.RuleName": ruleParameters` or `"RuleName": ruleParameters`
- "RuleSection.RuleName": any of the [available rules](https://codenarc.github.io/CodeNarc/codenarc-rule-index.html)
- "RuleSection.RuleName": any of the **[CodeNarc rules](https://codenarc.github.io/CodeNarc/codenarc-rule-index.html)**
- ruleParameters: can be just a severity override ( `"off"`, `"error"`, `"warning"`, `"info"` ) , or a property list :

@@ -82,12 +80,12 @@ - severity : off,error,warning,info

```javascript
module.exports = {
extends: "recommended",
rules: {
"comments.ClassJavadoc": 'off',
```json
{
"extends": "recommended",
"rules": {
"comments.ClassJavadoc": "off",
"formatting.Indentation": {
spacesPerIndentLevel: 4,
severity: "info"
"spacesPerIndentLevel": 4,
"severity": "info"
},
'UnnecessaryReturnKeyword': "error"
"UnnecessaryReturnKeyword": "error"
}

@@ -94,0 +92,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