-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
lint-ecosystem.js
59 lines (50 loc) · 1.42 KB
/
lint-ecosystem.js
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
'use strict'
const path = require('path')
const fs = require('fs')
const readline = require('readline')
const ecosystemDocFile = path.join(__dirname, '..', '..', 'docs', 'Guides', 'Ecosystem.md')
module.exports = async function ({ core }) {
const stream = await fs.createReadStream(ecosystemDocFile)
const rl = readline.createInterface({
input: stream,
crlfDelay: Infinity
});
const moduleNameRegex = /^\- \[\`(.+)\`\]/
let hasOutOfOrderItem = false
let lineNumber = 0
let inCommmunitySection = false
let modules = []
for await (const line of rl) {
lineNumber += 1
if (line.startsWith('#### [Community]')) {
inCommmunitySection = true
}
if (line.startsWith('#### [Community Tools]')) {
inCommmunitySection = false
}
if (inCommmunitySection === false) {
continue
}
if (line.startsWith('- [`') !== true) {
continue
}
const moduleName = moduleNameRegex.exec(line)[1]
if (modules.length > 0) {
if (compare(moduleName, modules.at(-1)) > 0) {
core.error(`line ${lineNumber}: ${moduleName} not listed in alphabetical order`)
hasOutOfOrderItem = true
}
}
modules.push(moduleName)
}
if (hasOutOfOrderItem === true) {
core.setFailed('Some ecosystem modules are not in alphabetical order.')
}
}
function compare(current, previous) {
return previous.localeCompare(
current,
'en',
{sensitivity: 'base'}
)
}