feat: use go tool
This commit is contained in:
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"line-length": {
|
||||
"line_length": 200
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
/test
|
||||
/node_modules
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) David Anson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
# markdownlint-rule-max-one-sentence-per-line
|
||||
|
||||
A custom markdownlint rule to enforce maximum one sentence per line.
|
||||
|
||||
## Overview
|
||||
|
||||
When writing documentation, line-length often is not the most important rule.
|
||||
Some projects tend to ignore line-length and prefer an approach to limit each line to maximum one sentence.
|
||||
For example this allows:
|
||||
|
||||
* **easy rearranging of sentences**:
|
||||
Most IDEs support to move whole lines with cursor keys.
|
||||
When there is only one sentence per line, you can easier move them around, and rearrange the structure.
|
||||
* **easier detection of complicated sentence structures**:
|
||||
If a sentence fits into one line, you can easily spot structures, which are too complicated or might need improvement.
|
||||
|
||||
For a better overview it often requires to split a sentence even over multiple lines, which we will not interfere with.
|
||||
This rule will only enforce maximum one sentence per line, but it will not rejoin sentences and adapt the structure, that one sentence will be on just one line.
|
||||
|
||||
## Installation
|
||||
|
||||
Use following command to install
|
||||
|
||||
```console
|
||||
npm install markdownlint-rule-max-one-sentence-per-line --save-dev
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Tags: `sentences`
|
||||
|
||||
Parameters:
|
||||
|
||||
* `context_length`: Size of context provided in error message (`integer`,
|
||||
default `14`)
|
||||
* `ignored_words`: Words which will be ignored during the detection
|
||||
(`string[]`, default `["ie","i.e","eg","e.g","etc","ex"]`)
|
||||
* `line_endings`: Recognized line-endings (`string[]`, default `[".","?","!"]`)
|
||||
* `sentence_start`: Regex for sentence start (`string`, default
|
||||
`^\s+(\w|[*_'"])`)
|
||||
* `indentation`: Defines the used indentation (`string`, default
|
||||
``)
|
||||
|
||||
Fixable: Some violations can be fixed by tooling
|
||||
|
||||
```markdown
|
||||
First sentence. Second sentence.
|
||||
|
||||
> First sentence. Second sentence.
|
||||
|
||||
* First sentence. Second sentence.
|
||||
```
|
||||
|
||||
should be:
|
||||
|
||||
```markdown
|
||||
First sentence.
|
||||
Second sentence.
|
||||
|
||||
> First sentence.
|
||||
> Second sentence.
|
||||
|
||||
* First sentence.
|
||||
Second sentence. <!-- indentation based on provided configuration -->
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
For usage with certain tools, please refer to the documentation of markdownlint, markdownlint-cli or the tool you are using.
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const indentFor = (string, indentation) => {
|
||||
// eslint-disable-next-line max-len
|
||||
const regex = new RegExp("^(?<indents>(" + indentation + ")*)(?<adds>- |> |>|\\* |\\d+\\. )?");
|
||||
const match = regex.exec(string);
|
||||
if (!match) {
|
||||
return "";
|
||||
}
|
||||
let indentSize = 0;
|
||||
if (match.groups.indents) {
|
||||
indentSize = match.groups.indents.length / indentation.length;
|
||||
}
|
||||
if (match.groups.adds) {
|
||||
if (match.groups.adds.includes(">")) {
|
||||
return indentation.repeat(indentSize) + match.groups.adds;
|
||||
}
|
||||
indentSize++;
|
||||
}
|
||||
return indentation.repeat(indentSize);
|
||||
};
|
||||
|
||||
module.exports.indentFor = indentFor;
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "markdownlint-rule-max-one-sentence-per-line",
|
||||
"version": "0.0.2",
|
||||
"description": "A custom markdownlint rule to enforce maximum one sentence per line",
|
||||
"main": "./rule.js",
|
||||
"keywords": [
|
||||
"markdownlint-rule",
|
||||
"markdownlint",
|
||||
"markdown",
|
||||
"lint"
|
||||
],
|
||||
"author": "Simon Schrottner",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/aepfli/markdownlint-rule-max-one-sentence-per-line",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/aepfli/markdownlint-rule-max-one-sentence-per-line.git"
|
||||
},
|
||||
"bugs": "https://github.com/aepfli/markdownlint-rule-max-one-sentence-per-line",
|
||||
"scripts": {
|
||||
"test": "ava test/*-tests.js",
|
||||
"lint": "npm run lint:es && npm run lint:md",
|
||||
"lint-fix": "npm run lint:es-fix && npm run lint:md-fix",
|
||||
"lint:es": "eslint --max-warnings 0 .",
|
||||
"lint:es-fix": "eslint --max-warnings 0 --fix .",
|
||||
"lint:md": "markdownlint '**/*.md' ",
|
||||
"lint:md-fix": "markdownlint --fix '**/*.md'"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"markdownlint-rule-helpers": "~0.18.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "5.2.0",
|
||||
"eslint": "8.34.0",
|
||||
"eslint-plugin-es": "4.1.0",
|
||||
"eslint-plugin-jsdoc": "40.0.0",
|
||||
"eslint-plugin-n": "15.6.1",
|
||||
"eslint-plugin-regexp": "1.12.0",
|
||||
"eslint-plugin-unicorn": "45.0.2",
|
||||
"markdownlint": "^0.27.0",
|
||||
"markdownlint-cli": "^0.33.0"
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const {
|
||||
addError
|
||||
} = require("markdownlint-rule-helpers");
|
||||
|
||||
const { indentFor } = require("./helper");
|
||||
|
||||
const isAfterIgnoredWord = (ignoredWords, line, i) => {
|
||||
for (const ignoredWord of ignoredWords) {
|
||||
const lastWordInLine = line.substring(i - ignoredWord.length, i);
|
||||
if (ignoredWord === lastWordInLine.toLowerCase()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
"names": [ "max-one-sentence-per-line" ],
|
||||
"description": "Max 1 sentence should be on a line",
|
||||
"information": new URL(
|
||||
"https://github.com/aepfli/markdownlint-rule-max-one-sentence-per-line"
|
||||
),
|
||||
"tags": [ "sentences" ],
|
||||
"function": (params, onError) => {
|
||||
|
||||
const ignoredWords = params.config.ignored_words ||
|
||||
[ "ie", "i.e", "eg", "e.g", "etc", "ex" ];
|
||||
const lineEndings = params.config.line_endings || [ ".", "?", "!" ];
|
||||
const sentenceStartRegex = params.config.sentence_start ||
|
||||
"^\\s+(\\w|[*_'\"])";
|
||||
const contextSize = Number(params.config.context_length || 14);
|
||||
const indentation = params.config.indentation || " ";
|
||||
|
||||
const sentenceStart = new RegExp(sentenceStartRegex);
|
||||
|
||||
const relevantTokens = [];
|
||||
for (let i = 0; i < params.tokens.length; i++) {
|
||||
const token = params.tokens[i];
|
||||
if (token.type === "paragraph_open" &&
|
||||
params.tokens[i + 1].type === "inline") {
|
||||
relevantTokens.push(params.tokens[i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
for (const relevantToken of relevantTokens) {
|
||||
|
||||
for (const token of relevantToken.children) {
|
||||
const lineNumber = token.lineNumber;
|
||||
if (token.type === "text") {
|
||||
const content = token.content;
|
||||
for (let i = 0; i < content.length - 2; i += 1) {
|
||||
|
||||
if (lineEndings.includes(content[i])) {
|
||||
const sentence = sentenceStart.exec(content.substr(i + 1));
|
||||
if (
|
||||
sentence !== null &&
|
||||
!isAfterIgnoredWord(ignoredWords, content, i)
|
||||
) {
|
||||
const spaces = sentence[1];
|
||||
const pointInLine = token.line.indexOf(content) + i;
|
||||
addError(
|
||||
onError,
|
||||
lineNumber,
|
||||
null,
|
||||
// eslint-disable-next-line max-len
|
||||
content.substr(Math.max(0, i - (contextSize / 2)), contextSize),
|
||||
[ pointInLine, spaces.length ],
|
||||
{
|
||||
"lineNumber": lineNumber,
|
||||
"editColumn": pointInLine + 2,
|
||||
"deleteCount": spaces.length,
|
||||
// eslint-disable-next-line max-len
|
||||
"insertText": "\n" + indentFor(relevantToken.line, indentation)
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user