Welcome to mirror list, hosted at ThFree Co, Russian Federation.

README.md « eslint-plugin-markdown « node_modules « eslint « tools - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4f212022c81355d3f440fab8c23187f3ce3b2d83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# eslint-plugin-markdown

![Screenshot](screenshot.png)

An [ESLint](http://eslint.org/) plugin to lint JavaScript in Markdown.

Supported extensions are `.markdown`, `.mdown`, `.mkdn`, and `.md`.

## Usage

Install the plugin:

```sh
npm install --save-dev eslint eslint-plugin-markdown
```

Add it to your `.eslintrc`:

```json
{
    "plugins": [
        "markdown"
    ]
}
```

Run ESLint on `.md` files:

```sh
eslint --ext md .
```

It will lint `js`, `javascript`, `jsx`, or `node` [fenced code blocks](https://help.github.com/articles/github-flavored-markdown/#fenced-code-blocks) in your Markdown documents:

    ```js
    // This gets linted
    var answer = 6 * 7;
    console.log(answer);
    ```

    ```JavaScript
    // This also gets linted

    /* eslint quotes: [2, "double"] */

    function hello() {
        console.log("Hello, world!");
    }
    hello();
    ```

    ```jsx
    // This gets linted too
    var div = <div className="jsx"></div>;
    ```

    ```node
    // And this
    console.log(process.version);
    ```

Blocks that don't specify either `js`, `javascript`, `jsx`, or `node` syntax are ignored:

    ```
    This is plain text and doesn't get linted.
    ```

    ```python
    print("This doesn't get linted either.")
    ```

## Configuration Comments

The processor will convert HTML comments immediately preceding a code block into JavaScript block comments and insert them at the beginning of the source code that it passes to ESLint. This permits configuring ESLint via configuration comments while keeping the configuration comments themselves hidden when the markdown is rendered. Comment bodies are passed through unmodified, so the plugin supports any [configuration comments](http://eslint.org/docs/user-guide/configuring) supported by ESLint itself.

This example enables the `browser` environment, disables the `no-alert` rule, and configures the `quotes` rule to prefer single quotes:

    <!-- eslint-env browser -->
    <!-- eslint-disable no-alert -->
    <!-- eslint quotes: ["error", "single"] -->

    ```js
    alert('Hello, world!');
    ```

Each code block in a file is linted separately, so configuration comments apply only to the code block that immediately follows.

    Assuming `no-alert` is enabled in `.eslintrc`, the first code block will have no error from `no-alert`:

    <!-- eslint-env browser -->
    <!-- eslint-disable no-alert -->

    ```js
    alert("Hello, world!");
    ```

    But the next code block will have an error from `no-alert`:

    <!-- eslint-env browser -->

    ```js
    alert("Hello, world!");
    ```

## Unsatisfiable Rules

Since code blocks are not files themselves but embedded inside a Markdown document, some rules do not apply to Markdown code blocks, and messages from these rules are automatically suppressed:

- `eol-last`

## Contributing

```sh
$ git clone https://github.com/eslint/eslint-plugin-markdown.git
$ cd eslint-plugin-markdown
$ npm link
$ npm link eslint-plugin-markdown
$ npm test
```

This project follows the [ESLint contribution guidelines](http://eslint.org/docs/developer-guide/contributing/).