Skip to content

Commit

Permalink
Merge pull request #2 from 343dev/improvement/cleaning
Browse files Browse the repository at this point in the history
Move to ESM
  • Loading branch information
343dev authored Mar 28, 2024
2 parents 2a6f4c1 + 6377c80 commit 566282e
Show file tree
Hide file tree
Showing 17 changed files with 8,073 additions and 3,852 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
root = true

[*]
indent_style = space
indent_style = tab
indent_size = 2
end_of_line = lf
charset = utf-8
Expand Down
6 changes: 0 additions & 6 deletions .eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [16.x, 18.x, 20.x, 21.x]

steps:
- uses: actions/checkout@v2
Expand Down
12 changes: 5 additions & 7 deletions .markdownlintrc.js → .markdownlintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ module.exports = {
},
remark: {
plugins: [
require('remark-preset-lint-markdown-style-guide'),
[require('remark-lint-list-item-indent'), 'space'],
[require('remark-lint-list-item-spacing'), { checkBlanks: true }],
[require('remark-lint-ordered-list-marker-value'), 'ordered'],
[require('remark-lint-emphasis-marker'), 'consistent'],
'remark-preset-lint-markdown-style-guide',
['remark-lint-list-item-indent', 'space'],
['remark-lint-list-item-spacing', { checkBlanks: true }],
['remark-lint-ordered-list-marker-value', 'ordered'],
['remark-lint-emphasis-marker', 'consistent'],
],

stringifySettings: {
bullet: '-',
listItemIndent: 'one',
fences: true,
}
},
typograf: {
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 3.0.0 (28.03.2024)

⚠️ Breaking changes.

- Package now
is [ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) only.
- Node.js version now is ≥16.
- Config file updated.

## 2.0.1 (10.06.2021)

Fixed several security vulnerabilities:
Expand Down
17 changes: 17 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Migration

## 2.0.1 → 3.0.0

Minimum required version of Node.js to use markdown-lint is now 16.0.0.

`.markdownlintrc.js` has been renamed to
[.markdownlintrc.cjs](./.markdownlintrc.cjs).

«cjs» file extension should be used now when you include external config using
`-c` or `--config` options.

It’s no longer necessary to use `require()` when including plugins in
`remark.plugins` config section.

Options `listItemIndent` and `fences` have been removed from
`remark.stringifySettings` section as they duplicated values set by default in
`remark-stringify`.

## 1.2.1 → 2.0.0

No post-upgrade action is required if you use a linter without a custom
Expand Down
36 changes: 7 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,10 @@ To install the tool and use it globally run:
npm install -g @343dev/markdown-lint
```

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

```bash
npm install --dev husky lint-staged @343dev/markdown-lint
```

## Project Setup

To automatically lint Markdown files on precommit you should setup `husky` and
`lint-staged` to work with `markdown-lint` in your project’s package.json.

Example:

```json
{
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.md": [
"markdown-lint --fix --typograph"
]
}
}
npm install --dev @343dev/markdown-lint
```

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

```bash
markdown-lint --fix --config ~/.markdownlintrc.js README.md
markdown-lint --fix --config ~/.markdownlintrc.cjs README.md
```

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

// disable rule `no-inline-padding`
[require('remark-lint-no-inline-padding'), false],
['remark-lint-no-inline-padding', false],

// set `*` as the only allowed marker for unordered list
[require('remark-lint-unordered-list-marker-style'), '*']
['remark-lint-unordered-list-marker-style', '*']
],

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

typograf: {
// rules API — https://github.com/typograf/typograf/blob/dev/docs/api_rules.md
// list of ruls — https://github.com/typograf/typograf/blob/dev/docs/RULES.en-US.md
// list of rules — https://github.com/typograf/typograf/blob/dev/docs/RULES.en-US.md
locale: ['ru', 'en-US'],
enableRules: [],
disableRules: [
Expand Down
38 changes: 8 additions & 30 deletions README.ru.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# @343dev/markdown-lint

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

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

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

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

```bash
npm install --dev husky lint-staged @343dev/markdown-lint
```

## Настройка проекта

Для автоматической проверки файлов перед коммитом необходимо настроить `husky` и
`lint-staged` на работу с `markdown-lint` в `package.json` вашего проекта.

Пример конфигурации:

```json
{
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.md": [
"markdown-lint --fix --typograph"
]
}
}
npm install --dev @343dev/markdown-lint
```

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

```bash
markdown-lint --fix --config ~/.markdownlintrc.js README.md
markdown-lint --fix --config ~/.markdownlintrc.cjs README.md
```

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

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

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

// remark-stringify обрабатывает тексты, когда `--fix` передан
Expand Down
53 changes: 30 additions & 23 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
#!/usr/bin/env node

const { program } = require('commander');
import fs from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const markdownLint = require('.');
const { prepareExtensions } = require('./lib/utils');
import { program } from 'commander';

const { version, description } = require('./package.json');
import markdownLint from './index.js';
import { prepareExtensions } from './lib/utils.js';

const dirname = path.dirname(fileURLToPath(import.meta.url));
const { version, description } = JSON.parse(await fs.readFile(path.join(dirname, 'package.json')));

program
.option('--fix', 'Automatically fix problems')
.option('--ext <value>', 'Specify file extensions', prepareExtensions, ['md', 'MD'])
.option('-t, --typograph', 'Enable typograph')
.option('-r, --recursive', 'Get files from provided directory and the entire subtree')
.option('-c, --config <file>', 'Use this configuration, overriding default options if present');
.option('--fix', 'Automatically fix problems')
.option('--ext <value>', 'Specify file extensions', prepareExtensions, ['md', 'MD'])
.option('-t, --typograph', 'Enable typograph')
.option('-r, --recursive', 'Get files from provided directory and the entire subtree')
.option('-c, --config <file>', 'Use this configuration, overriding default options if present');

program
.usage('[options] <dir> <file ...>')
.version(version, '-v, --version')
.description(description)
.parse(process.argv);
.usage('[options] <dir> <file ...>')
.version(version, '-v, --version')
.description(description)
.parse(process.argv);

if (!program.args.length) {
program.help();
if (program.args.length === 0) {
program.help();
} else {
markdownLint({
paths: program.args,
fix: program.fix,
ext: program.ext,
recursive: program.recursive,
config: program.config,
typograph: program.typograph,
});
const options = program.opts();

markdownLint({
paths: program.args,
fix: options.fix,
ext: options.ext,
recursive: options.recursive,
config: options.config,
typograph: options.typograph,
});
}
Loading

0 comments on commit 566282e

Please sign in to comment.