From cf259d40998f2956ab36158cd11beb5e15636331 Mon Sep 17 00:00:00 2001 From: KitoW Date: Mon, 8 Apr 2019 22:52:38 +0200 Subject: [PATCH] Updated MD047 name, desription and adjusted tests --- README.md | 2 +- doc/Rules.md | 11 ++++---- lib/md047.js | 13 ++++----- test/break-all-the-rules.md | 2 +- test/detailed-results-MD041-MD050.md | 2 +- .../detailed-results-MD041-MD050.results.json | 11 +++++++- test/markdownlint-test.js | 28 +++---------------- test/new_line_EOF.json | 4 --- test/new_line_EOF.md | 3 -- 9 files changed, 27 insertions(+), 49 deletions(-) delete mode 100644 test/new_line_EOF.json delete mode 100644 test/new_line_EOF.md diff --git a/README.md b/README.md index 7ace4445..3f82ae44 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ playground for learning and exploring. * **[MD043](doc/Rules.md#md043)** *required-headings/required-headers* - Required heading structure * **[MD044](doc/Rules.md#md044)** *proper-names* - Proper names should have the correct capitalization * **[MD045](doc/Rules.md#md045)** *no-alt-text* - Images should have alternate text (alt text) -* **[MD047](doc/Rules.md#md047)** *new-line-eof* - New lines at the end of file +* **[MD047](doc/Rules.md#md047)** *single-trailing-newline* - Files should end with a single newline character See [Rules.md](doc/Rules.md) for more details. diff --git a/doc/Rules.md b/doc/Rules.md index 3a59c93b..cab34a6a 100644 --- a/doc/Rules.md +++ b/doc/Rules.md @@ -1545,15 +1545,15 @@ Guidance for writing alternate text is available from the [W3C](https://www.w3.o [Wikipedia](https://en.wikipedia.org/wiki/Alt_attribute), and [other locations](https://www.phase2technology.com/blog/no-more-excuses-definitive-guide-alt-text-field). - + -## MD047 - New lines at the end of file +## MD047 - Files should end with a single newline character Tags: blank_lines -Aliases: new-line-eof +Aliases: single-trailing-newline -This rule is triggered when there is no new line at the end of the file. +This rule is triggered when there is no single newline character at the end of the file. Example that triggers the rule: @@ -1568,6 +1568,5 @@ To fix the violation, add new line at the end of the file: ```markdown # File ending with new line -This file ends with new line. - +This file ends with new line.\n ``` diff --git a/lib/md047.js b/lib/md047.js index b3f82b3a..7369a44f 100644 --- a/lib/md047.js +++ b/lib/md047.js @@ -3,20 +3,17 @@ "use strict"; const shared = require("./shared"); -const { isBlankLine } = shared; +const { addError, isBlankLine } = shared; module.exports = { - "names": [ "MD047", "new-line-eof" ], - "description": "New lines at the end of file", + "names": [ "MD047", "single-trailing-newline" ], + "description": "Files should end with a single newline character", "tags": [ "blank_lines" ], - "function": function rule(params, onError) { + "function": function MD047(params, onError) { const lastLineNumber = params.lines.length; const lastLine = params.lines[lastLineNumber - 1]; if (!isBlankLine(lastLine)) { - onError({ - "lineNumber": lastLineNumber, - "detail": "file does not end with new line" - }); + addError(onError, lastLineNumber); } } }; diff --git a/test/break-all-the-rules.md b/test/break-all-the-rules.md index 59884ab0..0f67ce86 100644 --- a/test/break-all-the-rules.md +++ b/test/break-all-the-rules.md @@ -78,4 +78,4 @@ code fence without language {MD040:73} markdownLint {MD044} -![](image.jpg) {MD045} +![](image.jpg) {MD045} {MD047} \ No newline at end of file diff --git a/test/detailed-results-MD041-MD050.md b/test/detailed-results-MD041-MD050.md index 8fada572..da98bec6 100644 --- a/test/detailed-results-MD041-MD050.md +++ b/test/detailed-results-MD041-MD050.md @@ -16,4 +16,4 @@ MarkDownLint. A [normal](link) and an [empty one]() and a [fragment](#one). -An image without alternate text ![](image.jpg) +An image without alternate text ![](image.jpg) \ No newline at end of file diff --git a/test/detailed-results-MD041-MD050.results.json b/test/detailed-results-MD041-MD050.results.json index f405fc6c..6591aa2d 100644 --- a/test/detailed-results-MD041-MD050.results.json +++ b/test/detailed-results-MD041-MD050.results.json @@ -45,7 +45,7 @@ "errorRange": [25, 13] }, { - "lineNumber": 20, + "lineNumber": 19, "ruleNames": [ "MD043", "required-headings", "required-headers" ], "ruleDescription": "Required heading structure", "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md043", @@ -88,5 +88,14 @@ "errorDetail": null, "errorContext": null, "errorRange": null + }, + { + "lineNumber": 19, + "ruleNames": [ "MD047", "single-trailing-newline" ], + "ruleDescription": "Files should end with a single newline character", + "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md047", + "errorDetail": null, + "errorContext": null, + "errorRange": null } ] \ No newline at end of file diff --git a/test/markdownlint-test.js b/test/markdownlint-test.js index e28c4005..9a2e6c83 100644 --- a/test/markdownlint-test.js +++ b/test/markdownlint-test.js @@ -808,7 +808,8 @@ module.exports.styleAll = function styleAll(test) { "MD040": [ 73 ], "MD041": [ 1 ], "MD042": [ 77 ], - "MD045": [ 81 ] + "MD045": [ 81 ], + "MD047": [ 81 ] } }; test.deepEqual(actualResult, expectedResult, "Undetected issues."); @@ -847,7 +848,8 @@ module.exports.styleRelaxed = function styleRelaxed(test) { "MD035": [ 61 ], "MD036": [ 65 ], "MD042": [ 77 ], - "MD045": [ 81 ] + "MD045": [ 81 ], + "MD047": [ 81 ] } }; test.deepEqual(actualResult, expectedResult, "Undetected issues."); @@ -2719,25 +2721,3 @@ $$\n` test.done(); }); }; - -module.exports.newLineAtTheEndOfFile = - function newLineAtTheEndOfFile(test) { - test.expect(2); - markdownlint({ - "files": "./test/new_line_EOF.md" - }, function callback(err, actual) { - test.ifError(err); - const expected = { "./test/new_line_EOF.md": - [ - { "lineNumber": 3, - "ruleNames": [ "MD047", "new-line-eof" ], - "ruleDescription": "New lines at the end of file", - "ruleInformation": `${homepage}/blob/v${version}/doc/Rules.md#md047`, - "errorDetail": "file does not end with new line", - "errorContext": null, - "errorRange": null } - ] }; - test.deepEqual(actual, expected, "Unexpected issues."); - test.done(); - }); - }; diff --git a/test/new_line_EOF.json b/test/new_line_EOF.json deleted file mode 100644 index 4970b843..00000000 --- a/test/new_line_EOF.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "default": true, - "MD047": false -} diff --git a/test/new_line_EOF.md b/test/new_line_EOF.md deleted file mode 100644 index 01488118..00000000 --- a/test/new_line_EOF.md +++ /dev/null @@ -1,3 +0,0 @@ -# File ending without new line - -This file ends without new line. \ No newline at end of file