-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEW Migrate documentation linting to a new repository
- Loading branch information
1 parent
ad970b8
commit 05093af
Showing
10 changed files
with
643 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const rules = require('@silverstripe/eslint-config/.eslintrc'); | ||
|
||
rules.plugins = ['markdown']; | ||
rules.overrides = [ | ||
{ | ||
files: ['**/*.md'], | ||
processor: 'markdown/markdown' | ||
}, | ||
{ | ||
files: ['**/*.md/*.js'], | ||
parserOptions: { | ||
ecmaFeatures: { | ||
impliedStrict: true | ||
} | ||
}, | ||
settings: { | ||
react: { | ||
version: '16' | ||
} | ||
}, | ||
rules: { | ||
// These rules are not appropriate for linting markdown code blocks | ||
'lines-around-comment': 'off', | ||
'import/no-unresolved': 'off', | ||
'import/extensions': 'off', | ||
'react/jsx-no-undef': 'off', | ||
'no-undef': 'off', | ||
'no-unused-expressions': 'off', | ||
'no-unused-vars': 'off', | ||
'brace-style': 'off', // it's useful to have comments before the else block | ||
// These rules are disabled because they are difficult to adhere to right now | ||
'jsx-a11y/label-has-associated-control': 'off', | ||
'react/prefer-stateless-function': 'off', | ||
} | ||
} | ||
]; | ||
rules.ignorePatterns = ['**/node_modules/**', '**/.eslintrc.js']; | ||
|
||
module.exports = rules; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/node_modules/ | ||
/vendor/ | ||
composer.lock | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
import markdownlint from 'markdownlint'; | ||
import enhancedProperNames from 'markdownlint-rule-enhanced-proper-names/src/enhanced-proper-names.js'; | ||
import titleCaseStyle from 'markdownlint-rule-title-case-style'; | ||
import { load } from 'js-yaml'; | ||
|
||
export default { | ||
ignores: ['**/node_modules/**'], | ||
customRules: [ | ||
enhancedProperNames, | ||
titleCaseStyle, | ||
], | ||
config: markdownlint.readConfigSync('./.markdownlint.yml', [ load ]), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
# Enable all rules with default settings as a baseline | ||
default: true | ||
|
||
# MD041: Ignore the frontmatter (metadata) title when checking for H1s | ||
first-line-h1: | ||
front_matter_title: '' | ||
|
||
# MD025: Ignore the frontmatter (metadata) title when checking for H1s | ||
single-h1: | ||
front_matter_title: '' | ||
|
||
# MD003: Enforce ATX style headings | ||
heading-style: | ||
style: 'atx' | ||
|
||
# MD049: Use asterisks for italics | ||
emphasis-style: | ||
style: 'asterisk' | ||
|
||
# MD050: Use asterisks for bold | ||
strong-style: | ||
style: 'asterisk' | ||
|
||
# MD004: Use hyphens for unordered lists | ||
ul-style: | ||
style: 'dash' | ||
|
||
# MD029: Always use 1. for ordered lists | ||
ol-prefix: | ||
style: 'one' | ||
|
||
# MD013: Disable line-length rule for now as it touches too many lines of doc | ||
line-length: false | ||
# line_length: 120 | ||
|
||
# MD010: Use two spaces for each tab (default was 1) | ||
no-hard-tabs: | ||
spaces_per_tab: 2 | ||
|
||
# MD031: Don't require empty lines after code blocks in lists | ||
blanks-around-fences: | ||
list_items: false | ||
|
||
# MD035: Enforce a style for horizontal rules. | ||
# Hyphens would be confusing since we use those for frontmatter (metadata) | ||
hr-style: | ||
style: '___' | ||
|
||
# MD046: Don't allow indented codeblocks | ||
code-block-style: | ||
style: 'fenced' | ||
|
||
# MD048: Use backticks for codeblocks | ||
code-fence-style: | ||
style: 'backtick' | ||
|
||
# MD040: Explicitly only allow some languages for code blocks | ||
# This helps with consistency (e.g. avoid having both yml and yaml) | ||
fenced-code-language: | ||
language_only: true | ||
allowed_languages: | ||
- 'bash' # use this instead of shell or env | ||
- 'css' | ||
- 'diff' | ||
- 'graphql' | ||
- 'html' | ||
- 'js' | ||
- 'json' | ||
- 'php' | ||
- 'scss' | ||
- 'ss' | ||
- 'sql' | ||
- 'text' | ||
- 'xml' | ||
- 'yml' | ||
|
||
# MD044: Disable in favour of the enhanced version which ignores custom anchors for headings | ||
# markdownlint-rule-enhanced-proper-names: Enforces capitalisation for specific names | ||
proper-names: off | ||
enhanced-proper-names: | ||
code_blocks: false | ||
heading_id: false | ||
names: | ||
- 'API' | ||
- 'type/api-break' # the GitHub label | ||
- 'CI' | ||
- 'CMS' | ||
- '/cms' # e.g. "silverstripe/cms" | ||
- '-cms' # e.g. "silverstripe/recipe-cms" | ||
- 'CSS' | ||
- 'GitHub' | ||
- 'GraphQL' | ||
- '/graphql' # e.g. "silverstripe/graphql" | ||
- 'HTTP' | ||
- 'JavaScript' | ||
- 'JS' | ||
- '.js' # e.g. "Node.js" | ||
- 'jQuery' | ||
- 'ORM' | ||
- 'PHP' | ||
- 'php-' # e.g. "php-intl extension" | ||
- 'SCSS' | ||
- 'Silverstripe' | ||
- 'silverstripe/' # e.g. "silverstripe/framework" | ||
- 'silverstripe-' # e.g. "silverstripe-vendormodule" | ||
- '@silverstripe.org' | ||
- 'TinyMCE' | ||
- 'UI' | ||
- 'URL' | ||
- 'YAML' | ||
|
||
# markdownlint-rule-title-case-style: Use sentence-style headings | ||
title-case-style: | ||
case: 'sentence' | ||
# commas in the following list are intentional and necessary since the plugin makes no distinction | ||
# between words and punctuation | ||
ignore: | ||
- 'Apache' | ||
- 'APIs' | ||
- 'Composer' | ||
- 'CTE' | ||
- 'GitHub' | ||
- 'GraphQL' | ||
- 'Huntr' | ||
- 'JavaScript' | ||
- 'I' | ||
- 'InnoDB' | ||
- 'Git' | ||
- 'jQuery' | ||
- 'jQuery,' | ||
- 'Lighttpd' | ||
- 'MyISAM' | ||
- 'MySQL' | ||
- 'Nginx' | ||
- 'Nginx,' | ||
- 'PHPUnit' | ||
- 'RFCs' | ||
- 'Silverstripe' | ||
- 'TinyMCE' | ||
- 'Transifex' | ||
- 'URLs' | ||
- 'WebP' | ||
|
||
# MD033: Allow specific HTML tags | ||
no-inline-html: | ||
allowed_elements: | ||
# br is necessary for new lines in tables | ||
- 'br' | ||
# accordians are okay | ||
- 'details' | ||
- 'summary' | ||
# description lists are okay | ||
- 'dl' | ||
- 'dd' | ||
- 'dt' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,93 @@ | ||
# Documentation lint | ||
# Documentation lint | ||
|
||
An abstraction around various documentation linters to make linting markdown documentation easy. | ||
|
||
> [!WARNING] | ||
> This repository is intended for use by commercially supported Silverstripe CMS modules. Its linting rules are opinionated and may include rules which are specific to the documentation style and syntax used by those modules. | ||
## Installation | ||
|
||
Add this package as a dev dependency | ||
|
||
```bash | ||
composer require --dev silverstripe/documentation-lint | ||
``` | ||
|
||
You'll also need to allow the `dealerdirect/phpcodesniffer-composer-installer` plugin in the repository (this won't affect downstream users) so that the slevomat PHP linting rules are pulled in correctly. | ||
|
||
```json | ||
{ | ||
// ... | ||
"config": { | ||
"allow-plugins": { | ||
"dealerdirect/phpcodesniffer-composer-installer": true | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Setup | ||
|
||
### Required software | ||
|
||
You need `nvm` (or `node` installed with the right version - see `.nvmrc`) and `yarn` installed. | ||
|
||
> [!WARNING] | ||
> If you're using a shell other than bash (e.g. zsh) you'll need to set your node version before running the linting script, since your `nvm` installation is probably not set up in a way that it can be used in bash. | ||
You also need `getopt` (enhanced) installed - which you probably do but the script will let you know if you don't. | ||
|
||
### Setup in the repository | ||
|
||
You must add a `.doclintrc` file to the root of the repository which has markdown documentation you want linted. This file must contain a relative path to the directory which holds your documentation, and that path must end with a `/`. | ||
|
||
For example: | ||
```text | ||
docs/en/ | ||
``` | ||
|
||
> [!WARNING] | ||
> Only the first line of the file will be used. | ||
## Usage | ||
|
||
Simply run the command. By default it will assume you're running it from the directory that holds the `.doclintrc` file and that you want to lint markdown, php, and javascript within `.md` files. | ||
|
||
```bash | ||
vendor/bin/doclint | ||
``` | ||
|
||
To lint for a specific module (e.g. if you have multiple modules installed) you can pass the relative path to the folder containing the `.doclintrc` file. | ||
|
||
```bash | ||
vendor/bin/doclint vendor/silverstripe/developer-docs | ||
``` | ||
|
||
If you want to specifically only lint one of markdown syntax, PHP codeblocks, or JavaScript codeblocks, use the [appropriate flag(s)](#flags). | ||
|
||
```bash | ||
vendor/bin/doclint -jp | ||
# or | ||
vendor/bin/doclint --with-js --with-php | ||
``` | ||
|
||
To automatically fix any problems that can be automatically fixed, pass the `--fix` flag. | ||
|
||
```bash | ||
vendor/bin/doclint -f | ||
# or | ||
vendor/bin/doclint --fix | ||
``` | ||
|
||
### Flags | ||
|
||
The following flags can be used with the `doclint` script: | ||
|
||
|long name|short name|description| | ||
|---|---|---| | ||
|`--fix`|`-f`|Fix any automatically fixable problems| | ||
|`--with-md`|`-m`|Lint markdown syntax| | ||
|`--with-js`|`-j`|Lint JavaScript code blocks| | ||
|`--with-php`|`-p`|Lint PHP code blocks| | ||
|
||
If any language flag is passed, only the languages that are passed will be linted (or fixed if `--fix` is passed). If no language flags are passed, all languages will be linted. |
Oops, something went wrong.