fix markdownlint-rules-grav-pages

This commit is contained in:
OniriCorpe 2024-03-02 04:33:13 +01:00
parent 36fed7866e
commit b190487475
25 changed files with 15787 additions and 7 deletions

View file

@ -1,5 +1,6 @@
{
"extends": "markdownlint-rules-grav-pages",
"extends": "markdownlint-rules-grav-pages/rules/frontmatter.schema.json",
"default": true,
"code-block-style": {
"style": "fenced"
},
@ -15,6 +16,9 @@
"ul-style": {
"style": "dash"
},
"ul-indent": {
"indent": 2
},
"heading-style": {
"style": "atx"
},
@ -27,6 +31,10 @@
"ol-prefix": {
"style": "ordered"
},
"no-trailing-punctuation": {
"punctuation": ".,;:"
},
"no-inline-html": false,
"fenced-code-language": {
"allowed_languages": [
"bash",
@ -50,7 +58,5 @@
"GitHub"
]
},
"line-length": {
"line_length": 180
}
"line-length": false
}

View file

@ -0,0 +1,10 @@
{
"extends": "airbnb-base",
"rules": {
"no-empty": ["error", { "allowEmptyCatch": true }],
"prefer-rest-params": "off",
"prefer-spread": "off",
"strict": "off",
"indent": ["error", 4]
}
}

View file

@ -0,0 +1,2 @@
/node_modules/
/.idea

View file

@ -0,0 +1,9 @@
language: node_js
node_js:
- "8"
- "9"
- "10"
- "11"
script:
- npm run lint
- npm run test

View file

@ -0,0 +1,79 @@
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [1.0.19](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.18...v1.0.19) (2022-05-18)
### [1.0.18](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.17...v1.0.18) (2022-02-08)
### [1.0.17](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.16...v1.0.17) (2022-02-03)
### [1.0.16](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.15...v1.0.16) (2020-03-15)
### [1.0.15](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.14...v1.0.15) (2019-12-30)
### [1.0.14](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.13...v1.0.14) (2019-07-11)
### [1.0.13](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.12...v1.0.13) (2019-05-10)
<a name="1.0.12"></a>
### [1.0.12](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.11...v1.0.12) (2019-02-14)
<a name="1.0.11"></a>
### [1.0.11](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.10...v1.0.11) (2018-12-04)
<a name="1.0.10"></a>
### [1.0.10](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.9...v1.0.10) (2018-10-23)
<a name="1.0.9"></a>
### [1.0.9](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.8...v1.0.9) (2018-10-03)
<a name="1.0.8"></a>
### [1.0.8](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.7...v1.0.8) (2018-09-14)
<a name="1.0.7"></a>
### [1.0.7](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.6...v1.0.7) (2018-08-28)
<a name="1.0.6"></a>
### [1.0.6](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.5...v1.0.6) (2018-08-28)
<a name="1.0.5"></a>
### [1.0.5](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.4...v1.0.5) (2018-08-20)
<a name="1.0.4"></a>
### [1.0.4](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.3...v1.0.4) (2018-08-09)
<a name="1.0.3"></a>
### [1.0.3](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.2...v1.0.3) (2018-08-09)
<a name="1.0.2"></a>
### [1.0.2](https://github.com/syseleven/markdownlint-rules-grav-pages/compare/v1.0.1...v1.0.2) (2018-07-30)
<a name="1.0.1"></a>
### 1.0.1 (2018-07-19)

View file

@ -1,5 +1,44 @@
# Markdown Lint Rules for Grav Pages
## source
[![Build Status](https://travis-ci.org/syseleven/markdownlint-rules-grav-pages.svg?branch=master)](https://travis-ci.org/syseleven/markdownlint-rules-grav-pages)
those files comes from <https://github.com/syseleven/markdownlint-rules-grav-pages>
This package contains additional linting rules for [markdownlint](https://github.com/DavidAnson/markdownlint)
that check if a Markdown file is a valid [Grav CMS](https://getgrav.org/) page.
## Rules
### valid-images
* Checks if a relatively referenced image is present.
### valid-internal-links
* Checks if a link to a another markdown file in the same repo is correct.
### valid-metadata-block
* Checks if a Frontmatter metadata block is present and valid.
## Usage
See https://github.com/DavidAnson/markdownlint/blob/master/doc/CustomRules.md
## Development
To lint all source files run:
```bash
$ npm run lint
```
To run all tests:
```bash
$ npm run test
```
To release a new version, ensure that the checkout is clean, then run:
```bash
$ npm run release && git push --follow-tags origin master && npm publish
```

View file

@ -0,0 +1,10 @@
module.exports = function flat(array) {
let result = [];
array.forEach((a) => {
result.push(a);
if (Array.isArray(a.children)) {
result = result.concat(flat(a.children));
}
});
return result;
};

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,42 @@
{
"name": "markdownlint-rules-grav-pages",
"version": "1.0.19",
"description": "Markdownlint rules for Grav Pages",
"license": "BSD-3-Clause",
"repository": "https://github.com/syseleven/markdownlint-rules-grav-pages",
"author": "Bastian Hofmann <b.hofmann@syseleven.de>",
"scripts": {
"lint": "eslint .",
"test": "jest tests",
"release": "standard-version"
},
"keywords": [
"markdownlint-rule"
],
"husky": {
"hooks": {
"pre-commit": "npm run lint && npm run test"
}
},
"dependencies": {
"jsonschema": "^1.2.5",
"markdown-it": "^12.3.2",
"markdownlint": "^0.25.1",
"markdownlint-cli": "^0.31.1",
"transliteration": "^2.1.8",
"yamljs": "^0.3.0"
},
"devDependencies": {
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-plugin-import": "^2.20.1",
"husky": "^4.2.3",
"jest": "^28.1.0",
"standard-version": "^9.5.0"
},
"jest": {
"testEnvironmentOptions": {
"url": "http://localhost"
}
}
}

View file

@ -0,0 +1,9 @@
{
"globals": {
"test": true,
"expect": true,
"describe": true,
"beforeEach": true,
"afterEach": true
}
}

View file

@ -0,0 +1,23 @@
# Valid Images Test
Valid image
![AltText](test.image)
Valid relative image
![AltText](../test.image)
Invalid image
![AltText](test.invalid)
Invalid relative image
![AltText](../invalid/test.image)
## Valid External Anchor
Valid image with modifying grav query
![AltText](test.image?resize=100,100)

View file

@ -0,0 +1,46 @@
# Valid Internal Links Test
Valid path
[Text](test.md)
Valid relative path
[Text](../valid-images/test.md)
Invalid path
[Text](test.invalid)
Valid relative path
[Text](../valid-images/invalid.md)
No file
[Text](../valid-images)
As child: valid [Text](test.md) invalid [Text](test.invalid)
[Anchor](#valid-anchor)
[Anchor](#invalid-anchor)
## Valid Anchor
Valid relative path with anchor
[Text](../valid-images/test.md#valid-external-anchor)
Valid relative path with invalid anchor
[Text](../valid-images/test.md#invalid-external-anchor)
## Anchor with question?
[Anchor](#anchor-with-question)
## Anchor with umlaut üÜß
[Anchor](#anchor-with-umlaut-ueuess)
[LinkWithoutSrc]()

View file

@ -0,0 +1,5 @@
---
title: VeryLongTitleVeryLongTitleVeryLongTitleVeryLongTitleVeryLongTitleVeryLongTitleVeryLongTitleVeryLongTitleVeryLongTitle
---
## Content

View file

@ -0,0 +1,6 @@
---
title: My Page
invalid: field
---
## Content

View file

@ -0,0 +1,5 @@
---
title: My Page
---
## Content

View file

@ -0,0 +1,11 @@
---
title: My Page
taxonomy:
category:
- one
- two
tag:
- tag
---
## Content

View file

@ -0,0 +1,31 @@
const markdownlint = require('markdownlint');
const validImagesRule = require('../rules/valid-images');
test('validate images', () => {
const src = `${__dirname}/assets/valid-images/test.md`;
const results = markdownlint.sync({
customRules: validImagesRule,
files: [src],
});
expect(results[src]).toEqual([
{
lineNumber: 13,
ruleNames: ['valid-images'],
ruleDescription: 'Rule that reports if a file has valid image references',
ruleInformation: null,
errorDetail: 'Image src \'test.invalid\' does not link to a valid file.',
errorContext: '![AltText](test.invalid)',
errorRange: null,
},
{
lineNumber: 17,
ruleNames: ['valid-images'],
ruleDescription: 'Rule that reports if a file has valid image references',
ruleInformation: null,
errorDetail: 'Image src \'../invalid/test.image\' does not link to a valid file.',
errorContext: '![AltText](../invalid/test.image)',
errorRange: null,
},
]);
});

View file

@ -0,0 +1,89 @@
const markdownlint = require('markdownlint');
const validInternalLinks = require('../rules/valid-internal-links');
test('validate internal link', () => {
const src = `${__dirname}/assets/valid-internal-links/test.md`;
const results = markdownlint.sync({
customRules: validInternalLinks,
files: [src],
config: {
default: true,
'no-trailing-punctuation': {
punctuation: '.,;:!',
},
},
});
expect(results[src]).toEqual([
{
errorContext: '[LinkWithoutSrc]()',
errorDetail: null,
errorRange: [1, 18],
lineNumber: 46,
ruleDescription: 'No empty links',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.25.1/doc/Rules.md#md042',
ruleNames: [
'MD042',
'no-empty-links',
],
},
{
lineNumber: 13,
ruleNames: ['valid-internal-links'],
ruleDescription: 'Rule that reports if a file has an internal link to an invalid file',
ruleInformation: null,
errorDetail: 'Relative link \'test.invalid\' does not link to a valid file.',
errorContext: '[Text](test.invalid)',
errorRange: null,
},
{
lineNumber: 17,
ruleNames: ['valid-internal-links'],
ruleDescription: 'Rule that reports if a file has an internal link to an invalid file',
ruleInformation: null,
errorDetail: 'Relative link \'../valid-images/invalid.md\' does not link to a valid file.',
errorContext: '[Text](../valid-images/invalid.md)',
errorRange: null,
},
{
lineNumber: 21,
ruleNames: ['valid-internal-links'],
ruleDescription: 'Rule that reports if a file has an internal link to an invalid file',
ruleInformation: null,
errorDetail: 'Relative link \'../valid-images\' does not link to a valid file.',
errorContext: '[Text](../valid-images)',
errorRange: null,
},
{
lineNumber: 23,
ruleNames: ['valid-internal-links'],
ruleDescription: 'Rule that reports if a file has an internal link to an invalid file',
ruleInformation: null,
errorDetail: 'Relative link \'test.invalid\' does not link to a valid file.',
errorContext: 'As child: valid [Text](test.md) invalid [Text](test.invalid)',
errorRange: null,
},
{
errorContext: '[Anchor](#invalid-anchor)',
errorDetail: "Did not find matching heading for anchor '#invalid-anchor'",
errorRange: null,
lineNumber: 26,
ruleDescription: 'Rule that reports if a file has an internal link to an invalid file',
ruleInformation: null,
ruleNames: [
'valid-internal-links',
],
},
{
errorContext: '[Text](../valid-images/test.md#invalid-external-anchor)',
errorDetail: "Did not find matching heading for anchor '#invalid-external-anchor'",
errorRange: null,
lineNumber: 36,
ruleDescription: 'Rule that reports if a file has an internal link to an invalid file',
ruleInformation: null,
ruleNames: [
'valid-internal-links',
],
},
]);
});

View file

@ -0,0 +1,60 @@
const markdownlint = require('markdownlint');
const validMetadataBlockRule = require('../rules/valid-metadata-block');
// TODO add more test cases
test('validate valid minimum block', () => {
const src = `${__dirname}/assets/valid-metadata-block/valid-minimum-block.md`;
const results = markdownlint.sync({
customRules: validMetadataBlockRule,
files: [src],
});
expect(results[src]).toEqual([]);
});
test('validate too long title', () => {
const src = `${__dirname}/assets/valid-metadata-block/invalid-too-long-title.md`;
const results = markdownlint.sync({
customRules: validMetadataBlockRule,
files: [src],
});
expect(results[src]).toEqual([{
errorContext: 'title: VeryLongTitleVeryLongTitleVeryLongTitleVeryLongTitleVeryLongTitleVeryLongTitleVeryLongTitleVeryLongTitleVeryLongTitle',
errorDetail: 'instance.title does not meet maximum length of 80',
errorRange: null,
lineNumber: 5,
ruleDescription: 'Rule that reports if a file does not have a valid grav metadata block',
ruleInformation: null,
ruleNames: ['valid-metadata-block'],
}]);
});
test('validate unrecognized property', () => {
const src = `${__dirname}/assets/valid-metadata-block/invalid-unrecognized-property.md`;
const results = markdownlint.sync({
customRules: validMetadataBlockRule,
files: [src],
});
expect(results[src]).toEqual([{
errorContext: 'title: My Page\ninvalid: field',
errorDetail: 'instance additionalProperty "invalid" exists in instance when not allowed',
errorRange: null,
lineNumber: 6,
ruleDescription: 'Rule that reports if a file does not have a valid grav metadata block',
ruleInformation: null,
ruleNames: ['valid-metadata-block'],
}]);
});
test('validate valid taxonomy', () => {
const src = `${__dirname}/assets/valid-metadata-block/valid-taxonomy.md`;
const results = markdownlint.sync({
customRules: validMetadataBlockRule,
files: [src],
});
expect(results[src]).toEqual([]);
});