Skip to content

Commit

Permalink
improving detection and adding testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
aepfli committed Feb 15, 2023
1 parent 403b4f4 commit 7df0645
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 19 deletions.
16 changes: 7 additions & 9 deletions demo/markdownlint-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1345,13 +1345,13 @@ module.exports.referenceLinkImageData =
// @ts-check

module.exports.deprecatedRuleNames = ["MD002", "MD006"];
module.exports.optionalRuleNames = ["MD002", "MD054"];
module.exports.fixableRuleNames = [
"MD004", "MD005", "MD006", "MD007", "MD009", "MD010",
"MD011", "MD012", "MD014", "MD018", "MD019", "MD020",
"MD021", "MD022", "MD023", "MD026", "MD027", "MD030",
"MD031", "MD032", "MD034", "MD037", "MD038", "MD039",
"MD044", "MD047", "MD049", "MD050", "MD051", "MD053", "MD054"
"MD044", "MD047", "MD049", "MD050", "MD051", "MD053",
"MD054"
];
module.exports.homepage = "https://github.com/DavidAnson/markdownlint";
module.exports.version = "0.27.0";
Expand All @@ -1371,7 +1371,7 @@ module.exports.version = "0.27.0";
const path = __webpack_require__(/*! node:path */ "?9a52");
const { promisify } = __webpack_require__(/*! node:util */ "?39e5");
const markdownIt = __webpack_require__(/*! markdown-it */ "markdown-it");
const { deprecatedRuleNames, optionalRuleNames } = __webpack_require__(/*! ./constants */ "../lib/constants.js");
const { deprecatedRuleNames } = __webpack_require__(/*! ./constants */ "../lib/constants.js");
const rules = __webpack_require__(/*! ./rules */ "../lib/rules.js");
const helpers = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
const cache = __webpack_require__(/*! ./cache */ "../lib/cache.js");
Expand Down Expand Up @@ -1674,9 +1674,6 @@ function getEffectiveConfig(ruleList, config, aliasToRuleNames) {
for (const ruleName of deprecatedRuleNames) {
effectiveConfig[ruleName] = false;
}
for (const ruleName of optionalRuleNames) {
effectiveConfig[ruleName] = false;
}
for (const key of Object.keys(config)) {
let value = config[key];
if (value) {
Expand Down Expand Up @@ -5073,9 +5070,10 @@ module.exports = {
line[i + 1] === " " &&
isCapitalizedAlphabetCharacter(line[i + 2]) &&
!isAfterIgnoredWord(ignoredWords, line, i)) {
addError(onError, lineIndex, null, line.substr(Math.max(0, i - (contextSize / 2)), contextSize), null, {
"lineNumber": lineIndex,
"editColumn": i + 2,
addError(onError, lineIndex + 1, null, line.substr(Math.max(0, i - (contextSize / 2)), contextSize), [i, 1], {
"lineNumber": lineIndex + 1,
"editColumn": i,
"deleteCount": 1,
"insertText": "\n"
});
}
Expand Down
1 change: 0 additions & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"use strict";

module.exports.deprecatedRuleNames = [ "MD002", "MD006" ];
module.exports.optionalRuleNames = [ "MD002", "MD054" ];
module.exports.fixableRuleNames = [
"MD004", "MD005", "MD006", "MD007", "MD009", "MD010",
"MD011", "MD012", "MD014", "MD018", "MD019", "MD020",
Expand Down
5 changes: 1 addition & 4 deletions lib/markdownlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const path = require("node:path");
const { promisify } = require("node:util");
const markdownIt = require("markdown-it");
const { deprecatedRuleNames, optionalRuleNames } = require("./constants");
const { deprecatedRuleNames } = require("./constants");
const rules = require("./rules");
const helpers = require("../helpers");
const cache = require("./cache");
Expand Down Expand Up @@ -324,9 +324,6 @@ function getEffectiveConfig(ruleList, config, aliasToRuleNames) {
for (const ruleName of deprecatedRuleNames) {
effectiveConfig[ruleName] = false;
}
for (const ruleName of optionalRuleNames) {
effectiveConfig[ruleName] = false;
}
for (const key of Object.keys(config)) {
let value = config[key];
if (value) {
Expand Down
12 changes: 7 additions & 5 deletions lib/md054.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ module.exports = {

const ignoredWords = params.config.ignored_words || [];
const lineEndings = params.config.line_endings || [ "." ];
const sentenceStartRegex = params.config.sentence_start || "\\s+(\\w|[*_'\"])";
const contextSize = Number(params.config.context_length || 14);

const sentenceStart = new RegExp(sentenceStartRegex);

forEachLine(
getLineMetadata(params),
(line, lineIndex) => {
let i = 0;

// Ignore headings
if (/^\s*#/.test(line)) {
return;
Expand All @@ -99,8 +101,8 @@ module.exports = {

if (
lineEndings.includes(line[i]) &&
line[i + 1] === " " &&
isCapitalizedAlphabetCharacter(line[i + 2]) &&
// looking ahead, so we cover more than just one space
sentenceStart.test(line.substr(i, 5)) &&
!isAfterIgnoredWord(ignoredWords, line, i)
) {
addError(
Expand All @@ -111,9 +113,9 @@ module.exports = {
[ i, 1 ],
{
"lineNumber": lineIndex + 1,
"editColumn": i,
"editColumn": i + 2,
"deleteCount": 1,
"insertText": "\n"
"insertText": "\nddddd"
}
);
}
Expand Down
3 changes: 3 additions & 0 deletions schema/.markdownlint.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
// Example markdownlint JSON(C) configuration with all properties set to their default value

// Default state for all rules
"default": true,
Expand Down Expand Up @@ -305,6 +306,8 @@
"?",
"!"
],
// Regex for sentence start
"sentence_start": "\\s+(\\w|[*_'\"])",
// Size of context provided in error message
"context_length": 14
}
Expand Down
2 changes: 2 additions & 0 deletions schema/.markdownlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,7 @@ MD054:
- "."
- "?"
- "!"
# Regex for sentence start
sentence_start: "\\s+(\\w|[*_'\"])"
# Size of context provided in error message
context_length: 14
5 changes: 5 additions & 0 deletions schema/build-config-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@ for (const rule of rules) {
},
"default": [ ".", "?", "!" ]
},
"sentence_start": {
"description": "Regex for sentence start",
"type": "string",
"default": "\\s+(\\w|[*_'\"])"
},
"context_length": {
"description": "Size of context provided in error message",
"type": "integer",
Expand Down
5 changes: 5 additions & 0 deletions schema/markdownlint-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,11 @@
"!"
]
},
"sentence_start": {
"description": "Regex for sentence start",
"type": "string",
"default": "\\s+(\\w|[*_'\"])"
},
"context_length": {
"description": "Size of context provided in error message",
"type": "integer",
Expand Down

0 comments on commit 7df0645

Please sign in to comment.