2019-04-05 12:36:12 +02:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const { addError, isBlankLine } = require("../helpers");
|
|
|
|
|
2024-02-27 20:42:09 -08:00
|
|
|
// eslint-disable-next-line jsdoc/valid-types
|
|
|
|
/** @type import("./markdownlint").Rule */
|
2019-04-05 12:36:12 +02:00
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD047", "single-trailing-newline" ],
|
|
|
|
"description": "Files should end with a single newline character",
|
|
|
|
"tags": [ "blank_lines" ],
|
2024-03-09 16:17:50 -08:00
|
|
|
"parser": "none",
|
2019-04-05 12:36:12 +02:00
|
|
|
"function": function MD047(params, onError) {
|
|
|
|
const lastLineNumber = params.lines.length;
|
|
|
|
const lastLine = params.lines[lastLineNumber - 1];
|
|
|
|
if (!isBlankLine(lastLine)) {
|
2019-08-16 19:56:52 -07:00
|
|
|
addError(
|
|
|
|
onError,
|
|
|
|
lastLineNumber,
|
2024-02-27 20:42:09 -08:00
|
|
|
undefined,
|
|
|
|
undefined,
|
2019-09-20 21:50:44 -07:00
|
|
|
[ lastLine.length, 1 ],
|
2019-08-16 19:56:52 -07:00
|
|
|
{
|
|
|
|
"insertText": "\n",
|
|
|
|
"editColumn": lastLine.length + 1
|
|
|
|
}
|
|
|
|
);
|
2019-04-05 12:36:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|