Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve Ecosystem.md linter to lint all sections #4258

Merged
merged 6 commits into from
Sep 9, 2022
26 changes: 15 additions & 11 deletions .github/scripts/lint-ecosystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,29 @@ module.exports = async function ({ core }) {
let inCommunitySection = false
let modules = []
let hasImproperFormat = false
let moduleName

for await (const line of rl) {
lineNumber += 1

if (line.startsWith('- [') === true) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can cache this startsWith since it is used again later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your suggestion, I've added a commit to address this change.
I've also added two more commits:

  • One commit to extend the functionality of the ordering to all sections.
  • Another commit to fix out of order modules in the Core section.

If you feel like the last two commits are irrelevant to this PR, or not required, I can drop them if you wish

P.S.: It might be easier to view the diff through the individual commits

Edit: I've refactored the file, this comment is a little out-of-date, please re-review the total diff again

moduleName = moduleNameRegex.exec(line)?.[1]
if (moduleName === undefined)
{
core.error(`line ${lineNumber}: improper pattern, module name should be enclosed with backticks`)
hasImproperFormat = true
continue
}
}

if (line.startsWith('#### [Community]')) {
inCommunitySection = true
}

if (line.startsWith('#### [Community Tools]')) {
inCommunitySection = false
}

if (inCommunitySection === false) {
continue
}
Expand All @@ -36,16 +50,6 @@ module.exports = async function ({ core }) {
continue
}

const moduleNameTest = moduleNameRegex.exec(line)

if (moduleNameTest === null)
{
core.error(`line ${lineNumber}: improper pattern, module name should be enclosed with backticks`)
hasImproperFormat = true
continue
}

const moduleName = moduleNameTest[1]
if (modules.length > 0) {
if (compare(moduleName, modules.at(-1)) > 0) {
core.error(`line ${lineNumber}: ${moduleName} not listed in alphabetical order`)
Expand All @@ -58,7 +62,7 @@ module.exports = async function ({ core }) {
if (hasOutOfOrderItem === true) {
core.setFailed('Some ecosystem modules are not in alphabetical order.')
}

if (hasImproperFormat === true) {
core.setFailed('Some ecosystem modules are improperly formatted.')
}
Expand Down