Skip to content

Commit 97613ab

Browse files
committed
Require Node.js 18 and move to ESM
1 parent 9adfa76 commit 97613ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+622
-575
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13-
- 16
14-
- 14
15-
- 12
13+
- 20
14+
- 18
1615
steps:
17-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v3
1817
with:
1918
submodules: true
2019
fetch-depth: 0
21-
- uses: actions/setup-node@v2
20+
- uses: actions/setup-node@v3
2221
with:
2322
node-version: ${{ matrix.node-version }}
2423
- run: npm install

cli.js

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env node
2-
'use strict';
3-
const meow = require('meow');
4-
const findReadmeFile = require('./lib/find-readme-file.js');
5-
const awesomeLint = require('./index.js');
2+
import process from 'node:process';
3+
import meow from 'meow';
4+
import findReadmeFile from './lib/find-readme-file.js';
5+
import awesomeLint from './index.js';
66

7-
const getReporter = name => {
8-
// Check if reporter is an npm package
7+
const getReporter = async name => {
8+
// Check if reporter is an npm package.
99
try {
10-
return require(name).report;
10+
const {report} = await import(name);
11+
return report;
1112
} catch (error) {
1213
if (error.code === 'MODULE_NOT_FOUND') {
1314
console.error(`No reporter found matching \`${name}\`. Using default reporter (vfile-reporter-pretty).`);
@@ -17,34 +18,31 @@ const getReporter = name => {
1718
}
1819
};
1920

20-
const main = async () => {
21-
const cli = meow(`
22-
Usage
23-
$ awesome-lint [url|filename]
24-
25-
Options
26-
--reporter, -r Use a custom reporter
27-
`, {
28-
flags: {
29-
reporter: {
30-
type: 'string',
31-
alias: 'r'
32-
}
33-
}
34-
});
21+
const cli = meow(`
22+
Usage
23+
$ awesome-lint [url|filename]
3524
36-
const input = cli.input[0];
25+
Options
26+
--reporter, -r Use a custom reporter
27+
`, {
28+
importMeta: import.meta,
29+
flags: {
30+
reporter: {
31+
type: 'string',
32+
shortFlag: 'r',
33+
},
34+
},
35+
});
3736

38-
const options = {};
37+
const input = cli.input[0];
3938

40-
options.filename = input ? input : findReadmeFile(process.cwd());
39+
const options = {};
4140

42-
const reporterName = cli.flags.reporter;
43-
if (reporterName) {
44-
options.reporter = getReporter(reporterName);
45-
}
41+
options.filename = input ?? findReadmeFile(process.cwd());
4642

47-
await awesomeLint.report(options);
48-
};
43+
const reporterName = cli.flags.reporter;
44+
if (reporterName) {
45+
options.reporter = await getReporter(reporterName);
46+
}
4947

50-
main();
48+
await awesomeLint.report(options);

config.js

Lines changed: 98 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,111 @@
1-
'use strict';
1+
import remarkLint from 'remark-lint';
2+
import blockquoteIndentation from 'remark-lint-blockquote-indentation';
3+
import checkboxCharacterStyle from 'remark-lint-checkbox-character-style';
4+
import checkboxContentIndent from 'remark-lint-checkbox-content-indent';
5+
import codeBlockStyle from 'remark-lint-code-block-style';
6+
import definitionCase from 'remark-lint-definition-case';
7+
import definitionSpacing from 'remark-lint-definition-spacing';
8+
import emphasisMarker from 'remark-lint-emphasis-marker';
9+
import fencedCodeMarker from 'remark-lint-fenced-code-marker';
10+
import fileExtension from 'remark-lint-file-extension';
11+
import finalNewline from 'remark-lint-final-newline';
12+
import hardBreakSpaces from 'remark-lint-hard-break-spaces';
13+
import headingStyle from 'remark-lint-heading-style';
14+
import linkTitleStyle from 'remark-lint-link-title-style';
15+
import listItemBulletIndent from 'remark-lint-list-item-bullet-indent';
16+
import listItemIndent from 'remark-lint-list-item-indent';
17+
import noAutoLinkWithoutProtocol from 'remark-lint-no-auto-link-without-protocol';
18+
import noBlockquoteWithoutMarker from 'remark-lint-no-blockquote-without-marker';
19+
import noEmphasisAsHeading from 'remark-lint-no-emphasis-as-heading';
20+
import noFileNameArticles from 'remark-lint-no-file-name-articles';
21+
import noFileNameConsecutiveDashes from 'remark-lint-no-file-name-consecutive-dashes';
22+
import noFileNameIrregularCharacters from 'remark-lint-no-file-name-irregular-characters';
23+
import noFileNameMixedCase from 'remark-lint-no-file-name-mixed-case';
24+
import noFileNameOuterDashes from 'remark-lint-no-file-name-outer-dashes';
25+
import noHeadingContentIndent from 'remark-lint-no-heading-content-indent';
26+
import noHeadingIndent from 'remark-lint-no-heading-indent';
27+
import noHeadingPunctuation from 'remark-lint-no-heading-punctuation';
28+
import noInlinePadding from 'remark-lint-no-inline-padding';
29+
import noMultipleToplevelHeadings from 'remark-lint-no-multiple-toplevel-headings';
30+
import noShellDollars from 'remark-lint-no-shell-dollars';
31+
import noTableIndentation from 'remark-lint-no-table-indentation';
32+
import noUndefinedReferences from 'remark-lint-no-undefined-references';
33+
import noUnneededFullReferenceImage from 'remark-lint-no-unneeded-full-reference-image';
34+
import noUnneededFullReferenceLink from 'remark-lint-no-unneeded-full-reference-link';
35+
import noUnusedDefinitions from 'remark-lint-no-unused-definitions';
36+
import orderedListMarkerStyle from 'remark-lint-ordered-list-marker-style';
37+
import orderedListMarkerValue from 'remark-lint-ordered-list-marker-value';
38+
import ruleStyle from 'remark-lint-rule-style';
39+
import strongMarker from 'remark-lint-strong-marker';
40+
import tableCellPadding from 'remark-lint-table-cell-padding';
41+
import tablePipeAlignment from 'remark-lint-table-pipe-alignment';
42+
import tablePipes from 'remark-lint-table-pipes';
43+
import unorderedListMarkerStyle from 'remark-lint-unordered-list-marker-style';
44+
import matchPunctuation from 'remark-lint-match-punctuation';
45+
import noRepeatPunctuation from 'remark-lint-no-repeat-punctuation';
46+
import doubleLink from 'remark-lint-double-link';
47+
import customRules from './rules/index.js';
248

3-
exports.plugins = [
4-
require('remark-lint'),
49+
const plugins = [
50+
remarkLint,
551

652
// Official plugins
7-
[require('remark-lint-blockquote-indentation'), 2],
8-
[require('remark-lint-checkbox-character-style'), 'consistent'],
9-
require('remark-lint-checkbox-content-indent'),
10-
[require('remark-lint-code-block-style'), 'fenced'],
11-
require('remark-lint-definition-case'),
12-
require('remark-lint-definition-spacing'),
13-
[require('remark-lint-emphasis-marker'), 'consistent'],
14-
[require('remark-lint-fenced-code-marker'), '`'],
15-
require('remark-lint-file-extension'),
16-
require('remark-lint-final-newline'),
17-
require('remark-lint-hard-break-spaces'),
18-
[require('remark-lint-heading-style'), 'atx'],
19-
[require('remark-lint-link-title-style'), '\''],
20-
require('remark-lint-list-item-bullet-indent'),
53+
[blockquoteIndentation, 2],
54+
[checkboxCharacterStyle, 'consistent'],
55+
checkboxContentIndent,
56+
[codeBlockStyle, 'fenced'],
57+
definitionCase,
58+
definitionSpacing,
59+
[emphasisMarker, 'consistent'],
60+
[fencedCodeMarker, '`'],
61+
fileExtension,
62+
finalNewline,
63+
hardBreakSpaces,
64+
[headingStyle, 'atx'],
65+
[linkTitleStyle, '\''],
2166
// TODO: this rule doesn't properly handle tab indents
2267
// require('remark-lint-list-item-content-indent'),
23-
[require('remark-lint-list-item-indent'), 'space'],
24-
require('remark-lint-no-auto-link-without-protocol'),
25-
require('remark-lint-no-blockquote-without-marker'),
26-
require('remark-lint-no-emphasis-as-heading'),
27-
require('remark-lint-no-file-name-articles'),
28-
require('remark-lint-no-file-name-consecutive-dashes'),
29-
require('remark-lint-no-file-name-irregular-characters'),
30-
require('remark-lint-no-file-name-mixed-case'),
31-
require('remark-lint-no-file-name-outer-dashes'),
32-
require('remark-lint-no-heading-content-indent'),
33-
require('remark-lint-no-heading-indent'),
34-
require('remark-lint-no-heading-punctuation'),
35-
require('remark-lint-no-inline-padding'),
36-
[require('remark-lint-no-multiple-toplevel-headings'), 1],
37-
require('remark-lint-no-shell-dollars'),
38-
require('remark-lint-no-table-indentation'),
39-
require('remark-lint-no-undefined-references'),
40-
require('remark-lint-no-unneeded-full-reference-image'),
41-
require('remark-lint-no-unneeded-full-reference-link'),
42-
require('remark-lint-no-unused-definitions'),
43-
[require('remark-lint-ordered-list-marker-style'), 'consistent'],
44-
[require('remark-lint-ordered-list-marker-value'), 'ordered'],
45-
[require('remark-lint-rule-style'), '---'],
46-
[require('remark-lint-strong-marker'), 'consistent'],
47-
[require('remark-lint-table-cell-padding'), 'consistent'],
48-
require('remark-lint-table-pipe-alignment'),
49-
require('remark-lint-table-pipes'),
50-
[require('remark-lint-unordered-list-marker-style'), 'consistent'],
68+
listItemBulletIndent,
69+
[listItemIndent, 'space'],
70+
noAutoLinkWithoutProtocol,
71+
noBlockquoteWithoutMarker,
72+
noEmphasisAsHeading,
73+
noFileNameArticles,
74+
noFileNameConsecutiveDashes,
75+
noFileNameIrregularCharacters,
76+
noFileNameMixedCase,
77+
noFileNameOuterDashes,
78+
noHeadingContentIndent,
79+
noHeadingIndent,
80+
noHeadingPunctuation,
81+
noInlinePadding,
82+
[noMultipleToplevelHeadings, 1],
83+
noShellDollars,
84+
noTableIndentation,
85+
noUndefinedReferences,
86+
noUnneededFullReferenceImage,
87+
noUnneededFullReferenceLink,
88+
noUnusedDefinitions,
89+
[orderedListMarkerStyle, 'consistent'],
90+
[orderedListMarkerValue, 'ordered'],
91+
[ruleStyle, '---'],
92+
[strongMarker, 'consistent'],
93+
[tableCellPadding, 'consistent'],
94+
tablePipeAlignment,
95+
tablePipes,
96+
[unorderedListMarkerStyle, 'consistent'],
5197

5298
// Third-party plugins
5399
// Disabled as it throws `file.warn is not a function`
54100
// require('remark-lint-no-empty-sections'),
55101

56-
require('remark-lint-match-punctuation'),
57-
require('remark-lint-no-repeat-punctuation'),
58-
require('remark-lint-double-link'),
102+
matchPunctuation,
103+
noRepeatPunctuation,
104+
doubleLink,
59105

60106
// Custom plugins
61-
...require('./rules/index.js')
107+
...customRules,
62108
];
109+
110+
export default plugins;
111+

index.js

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,50 @@
1-
'use strict';
2-
const path = require('path');
3-
const isUrl = require('is-url-superb');
4-
const isGithubUrl = require('is-github-url');
5-
const ora = require('ora');
6-
const remark = require('remark');
7-
const gitClone = require('git-clone');
8-
const globby = require('globby');
9-
const pify = require('pify');
10-
const rmfr = require('rmfr');
11-
const tempy = require('tempy');
12-
const toVfile = require('to-vfile');
13-
const vfileReporterPretty = require('vfile-reporter-pretty');
14-
const config = require('./config.js');
15-
const findReadmeFile = require('./lib/find-readme-file.js');
16-
const codeOfConductRule = require('./rules/code-of-conduct.js');
1+
import process from 'node:process';
2+
import path from 'node:path';
3+
import isUrl from 'is-url-superb';
4+
import isGithubUrl from 'is-github-url';
5+
import ora from 'ora';
6+
import {remark} from 'remark';
7+
import gitClone from 'git-clone';
8+
import {globbySync} from 'globby';
9+
import rmfr from 'rmfr';
10+
import {temporaryDirectory} from 'tempy';
11+
import {readSync as readVFileSync} from 'to-vfile';
12+
import vfileReporterPretty from 'vfile-reporter-pretty';
13+
import config from './config.js';
14+
import findReadmeFile from './lib/find-readme-file.js';
15+
import codeOfConductRule from './rules/code-of-conduct.js';
1716

1817
const lint = options => {
1918
options = {
20-
config,
21-
filename: 'readme.md',
22-
...options
19+
...options,
20+
config: options.config ?? config,
21+
filename: options.filename ?? 'readme.md',
2322
};
2423

25-
const readmeFile = globby.sync(options.filename.replace(/\\/g, '/'), {caseSensitiveMatch: false})[0];
24+
const readmeFile = globbySync(options.filename.replaceAll('\\', '/'), {caseSensitiveMatch: false})[0];
2625

2726
if (!readmeFile) {
2827
return Promise.reject(new Error(`Couldn't find the file ${options.filename}`));
2928
}
3029

31-
const readmeVFile = toVfile.readSync(path.resolve(readmeFile));
30+
const readmeVFile = readVFileSync(path.resolve(readmeFile));
3231
const {dirname} = readmeVFile;
3332
const processTasks = [{
3433
vfile: readmeVFile,
35-
plugins: options.config
34+
plugins: options.config,
3635
}];
3736

38-
const codeOfConductFile = globby.sync(['{code-of-conduct,code_of_conduct}.md', '.github/{code-of-conduct,code_of_conduct}.md'], {caseSensitiveMatch: false, cwd: dirname})[0];
37+
const codeOfConductFile = globbySync(['{code-of-conduct,code_of_conduct}.md', '.github/{code-of-conduct,code_of_conduct}.md'], {caseSensitiveMatch: false, cwd: dirname})[0];
3938
if (codeOfConductFile) {
40-
const codeOfConductVFile = toVfile.readSync(path.resolve(dirname, codeOfConductFile));
39+
const codeOfConductVFile = readVFileSync(path.resolve(dirname, codeOfConductFile));
4140
codeOfConductVFile.repoURL = options.repoURL;
4241
processTasks.push({
4342
vfile: codeOfConductVFile,
44-
plugins: [codeOfConductRule]
43+
plugins: [codeOfConductRule],
4544
});
4645
}
4746

48-
return Promise.all(processTasks.map(({vfile, plugins}) => pify(remark().use(plugins).process)(vfile)));
47+
return Promise.all(processTasks.map(({vfile, plugins}) => remark().use(plugins).process(vfile)));
4948
};
5049

5150
lint.report = async options => {
@@ -67,8 +66,8 @@ lint._report = async (options, spinner) => {
6766
throw new Error(`Invalid GitHub repo URL: ${options.filename}`);
6867
}
6968

70-
temporary = tempy.directory();
71-
await pify(gitClone)(options.filename, temporary);
69+
temporary = temporaryDirectory();
70+
await gitClone(options.filename, temporary);
7271

7372
const readme = findReadmeFile(temporary);
7473
if (!readme) {
@@ -112,4 +111,4 @@ lint._report = async (options, spinner) => {
112111
console.log(reporter(vfiles));
113112
};
114113

115-
module.exports = lint;
114+
export default lint;

lib/find-author-name.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
'use strict';
2-
const parse = require('parse-github-url');
3-
const readPkg = require('read-pkg');
1+
import parseGitHubUrl from 'parse-github-url';
2+
import {readPackageSync} from 'read-pkg';
43

5-
module.exports = ({repoURL, dirname}) => {
4+
export default function findAuthorName({repoURL, dirname}) {
65
if (repoURL) {
7-
return parse(repoURL).owner;
6+
return parseGitHubUrl(repoURL).owner;
87
}
98

109
try {
11-
const json = readPkg.sync({cwd: dirname});
12-
return parse(json.repository.url).owner;
10+
const json = readPackageSync({cwd: dirname});
11+
return parseGitHubUrl(json.repository.url).owner;
1312
} catch {}
14-
};
13+
}

lib/find-readme-file.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
'use strict';
1+
import fs from 'node:fs';
2+
import path from 'node:path';
23

3-
const fs = require('fs');
4-
const path = require('path');
5-
6-
module.exports = directory => {
4+
export default function findReadmeFile(directory) {
75
const readmeFile = fs.readdirSync(directory).find(filename => (
86
/readme|readme\.md|readme\.markdown|readme.txt/i.test(filename)
97
));
108

119
if (readmeFile) {
1210
return path.join(fs.realpathSync(directory), readmeFile);
1311
}
14-
};
12+
}

0 commit comments

Comments
 (0)