Skip to content

Commit

Permalink
NEW Migrate documentation linting to a new repository
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Apr 3, 2024
1 parent ad970b8 commit f5fcb38
Show file tree
Hide file tree
Showing 10 changed files with 630 additions and 1 deletion.
39 changes: 39 additions & 0 deletions .eslintrc.js
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;
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules/
/vendor/
composer.lock
yarn.lock
14 changes: 14 additions & 0 deletions .markdownlint-cli2.mjs
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 ]),
};
155 changes: 155 additions & 0 deletions .markdownlint.yml
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'
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
81 changes: 80 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,80 @@
# 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
```

## 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 `.ss-docs-lint` 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 `.ss-docs-lint` file and that you want to lint markdown, php, and javascript within `.md` files.

```bash
vendor/bin/ss-docs-lint
```

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 `.ss-docs-lint` file.

```bash
vendor/bin/ss-docs-lint 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/ss-docs-lint -jp
# or
vendor/bin/ss-docs-lint --with-js --with-php
```

To automatically fix any problems that can be automatically fixed, pass the `--fix` flag.

```bash
vendor/bin/ss-docs-lint -f
# or
vendor/bin/ss-docs-lint --fix
```

### Flags

The following flags can be used with the `ss-docs-lint` 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.
Loading

0 comments on commit f5fcb38

Please sign in to comment.