Skip to content

Commit

Permalink
Add lang to code blocks in Markdown (#5299)
Browse files Browse the repository at this point in the history
* Add lang to code blocks in Markdown

This change aims to make documents more readable and avoid syntax errors
by adding a language specifier to code blocks in Markdown.

To perform this task efficiently, I use two remark plugins:
- [remark-lint-code-block-syntax](https://github.com/ybiquitous/remark-lint-code-block-syntax)
- [remark-lint-fenced-code-flag](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-fenced-code-flag)

```diff
--- a/package.json
+++ b/package.json
@@ -66,7 +66,9 @@
   },
   "remarkConfig": {
     "plugins": [
-      "@stylelint/remark-preset"
+      "@stylelint/remark-preset",
+      "remark-lint-code-block-syntax",
+      "remark-lint-fenced-code-flag"
     ]
   },
   "jest": {
@@ -189,6 +191,8 @@
     "postcss-import": "^12.0.1",
     "prettier": "^2.2.1",
     "remark-cli": "^9.0.0",
+    "remark-lint-code-block-syntax": "^0.2.1",
+    "remark-lint-fenced-code-flag": "^2.0.1",
     "typescript": "^4.2.4"
   },
   "engines": {
```

Note: I do not recommend the addition of the plugins because they produce false positives.

* Remove deprecated files

* Remove deprecated files again
  • Loading branch information
ybiquitous committed May 14, 2021
1 parent e4b6141 commit 887f03e
Show file tree
Hide file tree
Showing 66 changed files with 94 additions and 92 deletions.
2 changes: 1 addition & 1 deletion lib/rules/alpha-value-notation/README.md
Expand Up @@ -81,7 +81,7 @@ For example with `"percentage"`.

Given:

```
```json
["opacity"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/at-rule-allowed-list/README.md
Expand Up @@ -15,7 +15,7 @@ Specify a list of allowed at-rules.

Given:

```
```json
["extend", "keyframes"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/at-rule-disallowed-list/README.md
Expand Up @@ -15,7 +15,7 @@ Specify a list of disallowed at-rules.

Given:

```
```json
["extend", "keyframes"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/at-rule-empty-line-before/README.md
Expand Up @@ -408,7 +408,7 @@ For example, with `"always"`.

Given:

```
```json
["import"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/at-rule-no-unknown/README.md
Expand Up @@ -52,7 +52,7 @@ The following patterns are _not_ considered violations:

Given:

```
```json
["/^my-/", "custom"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/at-rule-property-required-list/README.md
Expand Up @@ -15,7 +15,7 @@ Specify a list of required properties for an at-rule.

Given:

```
```json
{
"font-face": ["font-display", "font-family", "font-style"]
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/block-closing-brace-newline-after/README.md
Expand Up @@ -173,7 +173,7 @@ For example, with `"always"` or `"always-multi-line"`.

Given:

```
```json
["if", "else"]
```

Expand Down
4 changes: 2 additions & 2 deletions lib/rules/block-opening-brace-space-before/README.md
Expand Up @@ -179,7 +179,7 @@ color: pink;}

Given:

```
```json
["/fo/"]
```

Expand All @@ -200,7 +200,7 @@ The following patterns are _not_ considered violations:

Given:

```
```json
[":root"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/color-named/README.md
Expand Up @@ -148,7 +148,7 @@ For example with `"never"`.

Given:

```
```json
["/^my-/", "composes"]
```

Expand Down
4 changes: 2 additions & 2 deletions lib/rules/comment-empty-line-before/README.md
Expand Up @@ -172,8 +172,8 @@ Ignore comments matching the given regular expressions or strings.

For example, with `"always"` and given:

```
[/^ignore/, "string-ignore"]
```json
["/^ignore/", "string-ignore"]
```

The following comments are _not_ considered violations:
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/comment-pattern/README.md
Expand Up @@ -17,7 +17,7 @@ A string will be translated into a RegExp like so `new RegExp(yourString)` — 

Given the string:

```
```json
"foo .+"
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/comment-word-disallowed-list/README.md
Expand Up @@ -19,7 +19,7 @@ If a string is surrounded with `"/"` (e.g. `"/^TODO:/"`), it is interpreted as a

Given:

```
```json
["/^TODO:/", "badword"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/custom-media-pattern/README.md
Expand Up @@ -17,7 +17,7 @@ A string will be translated into a RegExp like so `new RegExp(yourString)` — 

Given the string:

```
```json
"foo-.+"
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/custom-property-pattern/README.md
Expand Up @@ -17,7 +17,7 @@ A string will be translated into a RegExp like so `new RegExp(yourString)` — 

Given the string:

```
```json
"foo-.+"
```

Expand Down
Expand Up @@ -114,7 +114,7 @@ Ignore duplicates of specific properties.

Given:

```
```json
["color", "/background-/"]
```

Expand Down
Expand Up @@ -151,7 +151,7 @@ a {

Given:

```
```json
["padding", "/border/"]
```

Expand Down
20 changes: 11 additions & 9 deletions lib/rules/declaration-property-unit-allowed-list/README.md
Expand Up @@ -17,7 +17,7 @@ If a property name is surrounded with `"/"` (e.g. `"/^animation/"`), it is inter

Given:

```
```json
{
"font-size": ["em", "px"],
"/^animation/": ["s"],
Expand Down Expand Up @@ -92,14 +92,16 @@ Ignore units that are inside a function.

For example, given:

```
{
"/^border/": ["px"],
"/^background/": ["%"],
},
{
"ignore": ["inside-function"],
},
```json
[
{
"/^border/": ["px"],
"/^background/": ["%"]
},
{
"ignore": ["inside-function"]
}
]
```

The following patterns are _not_ considered violations:
Expand Down
Expand Up @@ -17,7 +17,7 @@ If a property name is surrounded with `"/"` (e.g. `"/^animation/"`), it is inter

Given:

```
```json
{
"font-size": ["em", "px"],
"/^animation/": ["s"]
Expand Down
Expand Up @@ -23,7 +23,7 @@ Be careful with regex matching not to accidentally consider quoted string values

Given:

```
```json
{
"transform": ["/scale/"],
"whitespace": ["nowrap"],
Expand Down
Expand Up @@ -21,7 +21,7 @@ Be careful with regex matching not to accidentally consider quoted string values

Given:

```
```json
{
"transform": ["/scale3d/", "/rotate3d/", "/translate3d/"],
"position": ["fixed"],
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/font-family-no-duplicate-names/README.md
Expand Up @@ -59,7 +59,7 @@ a { font: normal 14px/32px -apple-system, BlinkMacSystemFont, sans-serif; }

Given:

```
```json
["/^My Font /", "monospace"]
```

Expand Down
Expand Up @@ -70,7 +70,7 @@ a { font-family: Helvetica, var(--font-family-common); }

Given:

```
```json
["custom-font"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/function-allowed-list/README.md
Expand Up @@ -17,7 +17,7 @@ If a string is surrounded with `"/"` (e.g. `"/^rgb/"`), it is interpreted as a r

Given:

```
```json
["scale", "rgba", "linear-gradient"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/function-disallowed-list/README.md
Expand Up @@ -17,7 +17,7 @@ If a string is surrounded with `"/"` (e.g. `"/^rgb/"`), it is interpreted as a r

Given:

```
```json
["scale", "rgba", "linear-gradient"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/function-name-case/README.md
Expand Up @@ -123,7 +123,7 @@ For example, with `"lower"`.

Given:

```
```json
["some-function", "/^get.*$/"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/function-url-scheme-allowed-list/README.md
Expand Up @@ -22,7 +22,7 @@ This rule ignores:

Given:

```
```json
["data", "/^http/"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/function-url-scheme-disallowed-list/README.md
Expand Up @@ -22,7 +22,7 @@ This rule ignores:

Given:

```
```json
["ftp", "/^http/"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/keyframes-name-pattern/README.md
Expand Up @@ -17,7 +17,7 @@ A string will be translated into a RegExp like so `new RegExp(yourString)` — 

Given the string:

```
```json
"foo-.+"
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/max-line-length/README.md
Expand Up @@ -126,7 +126,7 @@ Ignore any line that matches the given regex pattern, regardless of whether it i

Given:

```
```json
"/^@import\\s+/"
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/max-nesting-depth/README.md
Expand Up @@ -284,7 +284,7 @@ Ignore the specified at-rules.

For example, with `1` and given:

```
```json
["/^my-/", "media"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/media-feature-name-allowed-list/README.md
Expand Up @@ -15,7 +15,7 @@ Specify a list of allowed media feature names.

Given:

```
```json
["max-width", "/^my-/"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/media-feature-name-disallowed-list/README.md
Expand Up @@ -15,7 +15,7 @@ Specify a list of disallowed media feature names.

Given:

```
```json
["max-width", "/^my-/"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/media-feature-name-no-unknown/README.md
Expand Up @@ -67,7 +67,7 @@ The following patterns are _not_ considered violations:

Given:

```
```json
["/^my-/", "custom"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/media-feature-name-value-allowed-list/README.md
Expand Up @@ -27,7 +27,7 @@ as a regular expression. For example, `/width$/` will match `max-width` and

Given:

```
```json
{
"min-width": ["768px", "1024px"],
"/resolution/": ["/dpcm$/"]
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/number-max-precision/README.md
Expand Up @@ -54,7 +54,7 @@ For example, with `2`.

Given:

```
```json
["/^my-/", "%"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/property-allowed-list/README.md
Expand Up @@ -19,7 +19,7 @@ If a string is surrounded with `"/"` (e.g. `"/^background/"`), it is interpreted

Given:

```
```json
["display", "animation", "/^background/"]
```

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/property-disallowed-list/README.md
Expand Up @@ -17,7 +17,7 @@ If a string is surrounded with `"/"` (e.g. `"/^background/"`), it is interpreted

Given:

```
```json
["text-rendering", "animation", "/^background/"]
```

Expand Down
6 changes: 3 additions & 3 deletions lib/rules/property-no-unknown/README.md
Expand Up @@ -81,7 +81,7 @@ a {

Given:

```
```json
["/^my-/", "custom"]
```

Expand Down Expand Up @@ -114,7 +114,7 @@ Skips checking properties of the given selectors against this rule.

Given:

```
```json
[":root"]
```

Expand All @@ -133,7 +133,7 @@ Ignores properties nested within specified at-rules.

Given:

```
```json
["supports"]
```

Expand Down

0 comments on commit 887f03e

Please sign in to comment.