Skip to content

Commit

Permalink
Use os.EOL
Browse files Browse the repository at this point in the history
  • Loading branch information
nvuillam committed Jul 8, 2020
1 parent dd8b987 commit f42dfac
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [5.4.2] 2020-07-08

- Use os.EOL [(#65)](https://github.com/nvuillam/npm-groovy-lint/pull/65) solving [(#63)](https://github.com/nvuillam/npm-groovy-lint/issues/63) --fix for indentation adds CRLF line-endings to all files it touches

## [5.4.1] 2020-07-01

- CodeNarcServer listens to localhost only [(#59)](https://github.com/nvuillam/npm-groovy-lint/pull/59) solving [(#56)](https://github.com/nvuillam/npm-groovy-lint/issues/56)
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,21 @@ This package uses :
## RELEASE NOTES
## [5.4.1] 2020-07-01
### [5.4.2] 2020-07-08
- Use os.EOL [(#65)](https://github.com/nvuillam/npm-groovy-lint/pull/65) solving [(#63)](https://github.com/nvuillam/npm-groovy-lint/issues/63) --fix for indentation adds CRLF line-endings to all files it touches
### [5.4.1] 2020-07-01
- CodeNarcServer listens to localhost only [(#59)](https://github.com/nvuillam/npm-groovy-lint/pull/59) solving [(#56)](https://github.com/nvuillam/npm-groovy-lint/issues/56)
- Replace @analytics/segment with @amplitude/node for anonymous stats
## [5.3.0] 2020-06-29
### [5.3.0] 2020-06-29
- New option **--failon** , replacing `--failonerror`,`--failonwarning` and `--failoninfo`. It can take error, warning or info values (default: none). Previous options remain working but are deprecated and will be removed in a future major version
- Update help for `--fixrules` option
## [5.1.0] 2020-06-04
### [5.1.0] 2020-06-04
- Install Java 8 using node-jre in case java version found is higher than Java 11 (CodeNarc compatibility is Java 8 to 11)
Expand Down
2 changes: 1 addition & 1 deletion lib/codenarc-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function prepareCodeNarcCall(options) {
cnFiles = "**/" + tmpFileNm;
}

await fse.writeFile(result.tmpGroovyFileName, options.source.replace(/\r?\n/g, "\r\n"));
await fse.writeFile(result.tmpGroovyFileName, options.source.replace(/\r?\n/g, os.EOL));
debug(`CREATE GROOVY temp file ${result.tmpGroovyFileName} with input source, as CodeNarc requires physical files`);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/groovy-lint-fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const fse = require("fs-extra");
const cliProgress = require("cli-progress");
const debug = require("debug")("npm-groovy-lint");
const os = require("os");
const { getNpmGroovyLintRules, getFormattingRulesToAlwaysRun } = require("./groovy-lint-rules.js");
const { evaluateVariables, getSourceLines } = require("./utils.js");

Expand Down Expand Up @@ -208,7 +209,7 @@ class NpmGroovyLintFix {
);
fixedInFileNb = fixedInFileNb + fixedNb;
}
const newSources = allLines.join("\r\n");
const newSources = allLines.join(os.EOL);
this.updatedLintResult.files[fileNm].updatedSource = newSources;
// Write new file content if it has been updated
if (this.options.save && fixedInFileNb > 0) {
Expand Down
3 changes: 2 additions & 1 deletion lib/groovy-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// Imports
const debug = require("debug")("npm-groovy-lint");
const os = require("os");
const performance = require("perf_hooks").performance;

const NpmGroovyLintFix = require("./groovy-lint-fix");
Expand Down Expand Up @@ -183,7 +184,7 @@ class NpmGroovyLint {
versions.push("Embeds:");
versions.push(`- CodeNarc version ${NPM_GROOVY_LINT_CONSTANTS["CodeNarcVersion"]}`);
versions.push(`- Groovy version ${NPM_GROOVY_LINT_CONSTANTS["GroovyVersion"]} (superlite)`);
const versionsOut = versions.join("\n");
const versionsOut = versions.join(os.EOL);
console.info(versionsOut);
this.outputString = versionsOut;
return false;
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/FileEndsWithoutNewline.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// File ends without new line
const os = require("os");

const rule = {
scope: "file",
Expand All @@ -7,7 +8,7 @@ const rule = {
label: "Add new line at the end of file",
type: "function",
func: allLines => {
return (allLines.join("\r\n") + "\r\n").split("\r\n");
return (allLines.join(os.EOL) + os.EOL).split(os.EOL);
}
},
tests: [
Expand Down
3 changes: 2 additions & 1 deletion lib/test/lint-fix.rules.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! /usr/bin/env node
"use strict";
const os = require("os");
const NpmGroovyLint = require("../groovy-lint.js");
const { getNpmGroovyLintRules } = require("../groovy-lint-rules.js");
let assert = require("assert");
Expand Down Expand Up @@ -40,7 +41,7 @@ describe("Check rules auto-fixes", () => {
async function checkRuleFix(ruleName, testRule) {
let fixRules = ruleName;
// Call linter & fixer
const source = testRule.sourceBefore.replace(/\r?\n/g, "\r\n");
const source = testRule.sourceBefore.replace(/\r\n/g, os.EOL);
const npmGroovyLintConfig = {
source: source,
rulesets: fixRules,
Expand Down
1 change: 1 addition & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const debug = require("debug")("npm-groovy-lint");
const decodeHtml = require("decode-html");
const fse = require("fs-extra");
const os = require("os");

function addImport(allLineLs, classToImport) {
// Check if import is already there
Expand Down

0 comments on commit f42dfac

Please sign in to comment.