Skip to content

Commit 566282e

Browse files
authoredMar 28, 2024··
Merge pull request #2 from 343dev/improvement/cleaning
Move to ESM
2 parents 2a6f4c1 + 6377c80 commit 566282e

17 files changed

+8073
-3852
lines changed
 

‎.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
root = true
33

44
[*]
5-
indent_style = space
5+
indent_style = tab
66
indent_size = 2
77
end_of_line = lf
88
charset = utf-8

‎.eslintrc.js

-6
This file was deleted.

‎.github/workflows/node.js.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
node-version: [14.x, 16.x, 18.x]
19+
node-version: [16.x, 18.x, 20.x, 21.x]
2020

2121
steps:
2222
- uses: actions/checkout@v2

‎.markdownlintrc.js ‎.markdownlintrc.cjs

+5-7
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ module.exports = {
99
},
1010
remark: {
1111
plugins: [
12-
require('remark-preset-lint-markdown-style-guide'),
13-
[require('remark-lint-list-item-indent'), 'space'],
14-
[require('remark-lint-list-item-spacing'), { checkBlanks: true }],
15-
[require('remark-lint-ordered-list-marker-value'), 'ordered'],
16-
[require('remark-lint-emphasis-marker'), 'consistent'],
12+
'remark-preset-lint-markdown-style-guide',
13+
['remark-lint-list-item-indent', 'space'],
14+
['remark-lint-list-item-spacing', { checkBlanks: true }],
15+
['remark-lint-ordered-list-marker-value', 'ordered'],
16+
['remark-lint-emphasis-marker', 'consistent'],
1717
],
1818

1919
stringifySettings: {
2020
bullet: '-',
21-
listItemIndent: 'one',
22-
fences: true,
2321
}
2422
},
2523
typograf: {

‎CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## 3.0.0 (28.03.2024)
4+
5+
⚠️ Breaking changes.
6+
7+
- Package now
8+
is [ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) only.
9+
- Node.js version now is ≥16.
10+
- Config file updated.
11+
312
## 2.0.1 (10.06.2021)
413

514
Fixed several security vulnerabilities:

‎MIGRATION.md

+17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Migration
22

3+
## 2.0.1 → 3.0.0
4+
5+
Minimum required version of Node.js to use markdown-lint is now 16.0.0.
6+
7+
`.markdownlintrc.js` has been renamed to
8+
[.markdownlintrc.cjs](./.markdownlintrc.cjs).
9+
10+
«cjs» file extension should be used now when you include external config using
11+
`-c` or `--config` options.
12+
13+
It’s no longer necessary to use `require()` when including plugins in
14+
`remark.plugins` config section.
15+
16+
Options `listItemIndent` and `fences` have been removed from
17+
`remark.stringifySettings` section as they duplicated values set by default in
18+
`remark-stringify`.
19+
320
## 1.2.1 → 2.0.0
421

522
No post-upgrade action is required if you use a linter without a custom

‎README.md

+7-29
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,10 @@ To install the tool and use it globally run:
3131
npm install -g @343dev/markdown-lint
3232
```
3333

34-
To install the tool into the project and setup pre-commit hook run:
34+
To install the tool into the project:
3535

3636
```bash
37-
npm install --dev husky lint-staged @343dev/markdown-lint
38-
```
39-
40-
## Project Setup
41-
42-
To automatically lint Markdown files on precommit you should setup `husky` and
43-
`lint-staged` to work with `markdown-lint` in your project’s package.json.
44-
45-
Example:
46-
47-
```json
48-
{
49-
"husky": {
50-
"hooks": {
51-
"pre-commit": "lint-staged"
52-
}
53-
},
54-
"lint-staged": {
55-
"*.md": [
56-
"markdown-lint --fix --typograph"
57-
]
58-
}
59-
}
37+
npm install --dev @343dev/markdown-lint
6038
```
6139

6240
## CLI Usage
@@ -103,7 +81,7 @@ You may use your own configuration file by passing the path to that file using
10381
`--config` option:
10482

10583
```bash
106-
markdown-lint --fix --config ~/.markdownlintrc.js README.md
84+
markdown-lint --fix --config ~/.markdownlintrc.cjs README.md
10785
```
10886

10987
Example of configuration file:
@@ -120,13 +98,13 @@ module.exports = {
12098
// plugins for remark-lint
12199
plugins: [
122100
// print errors when there're lines longer that 120 characters
123-
[require('remark-lint-maximum-line-length'), 120],
101+
['remark-lint-maximum-line-length', 120],
124102

125103
// disable rule `no-inline-padding`
126-
[require('remark-lint-no-inline-padding'), false],
104+
['remark-lint-no-inline-padding', false],
127105

128106
// set `*` as the only allowed marker for unordered list
129-
[require('remark-lint-unordered-list-marker-style'), '*']
107+
['remark-lint-unordered-list-marker-style', '*']
130108
],
131109

132110
// settings for remark-stringify which is used when `--fix` is passed
@@ -138,7 +116,7 @@ module.exports = {
138116

139117
typograf: {
140118
// rules API — https://github.com/typograf/typograf/blob/dev/docs/api_rules.md
141-
// list of ruls — https://github.com/typograf/typograf/blob/dev/docs/RULES.en-US.md
119+
// list of rules — https://github.com/typograf/typograf/blob/dev/docs/RULES.en-US.md
142120
locale: ['ru', 'en-US'],
143121
enableRules: [],
144122
disableRules: [

‎README.ru.md

+8-30
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# @343dev/markdown-lint
22

33
<img align="right" width="192" height="159"
4-
alt="Аватар: Яркое градиентное лого Markdown со звёздочкой"
5-
src="./logo.png">
4+
alt="Аватар: Яркое градиентное лого Markdown со звёздочкой"
5+
src="./logo.png">
66

77
[![npm](https://img.shields.io/npm/v/@343dev/markdown-lint.svg)](https://www.npmjs.com/package/@343dev/markdown-lint)
88

@@ -31,32 +31,10 @@ JS, CSS и иные файлы проекта. Потому создали эт
3131
npm install -g @343dev/markdown-lint
3232
```
3333

34-
Для установки и настройки на pre-commit хук:
34+
Для установки в проект:
3535

3636
```bash
37-
npm install --dev husky lint-staged @343dev/markdown-lint
38-
```
39-
40-
## Настройка проекта
41-
42-
Для автоматической проверки файлов перед коммитом необходимо настроить `husky` и
43-
`lint-staged` на работу с `markdown-lint` в `package.json` вашего проекта.
44-
45-
Пример конфигурации:
46-
47-
```json
48-
{
49-
"husky": {
50-
"hooks": {
51-
"pre-commit": "lint-staged"
52-
}
53-
},
54-
"lint-staged": {
55-
"*.md": [
56-
"markdown-lint --fix --typograph"
57-
]
58-
}
59-
}
37+
npm install --dev @343dev/markdown-lint
6038
```
6139

6240
## Работа с CLI
@@ -104,7 +82,7 @@ markdown-lint --fix README.md
10482
`--config` указать путь до него:
10583

10684
```bash
107-
markdown-lint --fix --config ~/.markdownlintrc.js README.md
85+
markdown-lint --fix --config ~/.markdownlintrc.cjs README.md
10886
```
10987

11088
Пример конфигурации:
@@ -121,13 +99,13 @@ module.exports = {
12199
// применяем настройки для remark-lint
122100
plugins: [
123101
// объявляем линтеру, что максимальная длина строки теперь равна 120 символам
124-
[require('remark-lint-maximum-line-length'), 120],
102+
['remark-lint-maximum-line-length', 120],
125103

126104
// отключаем правило `no-inline-padding`
127-
[require('remark-lint-no-inline-padding'), false],
105+
['remark-lint-no-inline-padding', false],
128106

129107
// объявляем линтеру, что мы теперь используем `*` как маркер списка
130-
[require('remark-lint-unordered-list-marker-style'), '*']
108+
['remark-lint-unordered-list-marker-style', '*']
131109
],
132110

133111
// remark-stringify обрабатывает тексты, когда `--fix` передан

‎cli.js

+30-23
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
11
#!/usr/bin/env node
22

3-
const { program } = require('commander');
3+
import fs from 'node:fs/promises';
4+
import path from 'node:path';
5+
import { fileURLToPath } from 'node:url';
46

5-
const markdownLint = require('.');
6-
const { prepareExtensions } = require('./lib/utils');
7+
import { program } from 'commander';
78

8-
const { version, description } = require('./package.json');
9+
import markdownLint from './index.js';
10+
import { prepareExtensions } from './lib/utils.js';
11+
12+
const dirname = path.dirname(fileURLToPath(import.meta.url));
13+
const { version, description } = JSON.parse(await fs.readFile(path.join(dirname, 'package.json')));
914

1015
program
11-
.option('--fix', 'Automatically fix problems')
12-
.option('--ext <value>', 'Specify file extensions', prepareExtensions, ['md', 'MD'])
13-
.option('-t, --typograph', 'Enable typograph')
14-
.option('-r, --recursive', 'Get files from provided directory and the entire subtree')
15-
.option('-c, --config <file>', 'Use this configuration, overriding default options if present');
16+
.option('--fix', 'Automatically fix problems')
17+
.option('--ext <value>', 'Specify file extensions', prepareExtensions, ['md', 'MD'])
18+
.option('-t, --typograph', 'Enable typograph')
19+
.option('-r, --recursive', 'Get files from provided directory and the entire subtree')
20+
.option('-c, --config <file>', 'Use this configuration, overriding default options if present');
1621

1722
program
18-
.usage('[options] <dir> <file ...>')
19-
.version(version, '-v, --version')
20-
.description(description)
21-
.parse(process.argv);
23+
.usage('[options] <dir> <file ...>')
24+
.version(version, '-v, --version')
25+
.description(description)
26+
.parse(process.argv);
2227

23-
if (!program.args.length) {
24-
program.help();
28+
if (program.args.length === 0) {
29+
program.help();
2530
} else {
26-
markdownLint({
27-
paths: program.args,
28-
fix: program.fix,
29-
ext: program.ext,
30-
recursive: program.recursive,
31-
config: program.config,
32-
typograph: program.typograph,
33-
});
31+
const options = program.opts();
32+
33+
markdownLint({
34+
paths: program.args,
35+
fix: options.fix,
36+
ext: options.ext,
37+
recursive: options.recursive,
38+
config: options.config,
39+
typograph: options.typograph,
40+
});
3441
}

0 commit comments

Comments
 (0)
Please sign in to comment.