Skip to content

Commit

Permalink
chore: improve Ecosystem.md linter to check for improper module nam…
Browse files Browse the repository at this point in the history
…e patterns (#4257)

* chore: improve `Ecosystem.md` linting script

Improve ecosystem linting script by returning an error in case of an improperly added module name pattern (i.e., not enclosed with backticks)

* Improve ecosystem linting to include all mis-formatted in error msg

* Check for misformatted module patterns in all ecosystem file sections

* fixup! Improve ecosystem linting to include all mis-formatted in error msg

* revert: limit ecosystem linting to community section only
  • Loading branch information
nooreldeensalah committed Sep 7, 2022
1 parent 16b25c8 commit af27b78
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions .github/scripts/lint-ecosystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,36 @@ module.exports = async function ({ core }) {
const moduleNameRegex = /^\- \[\`(.+)\`\]/
let hasOutOfOrderItem = false
let lineNumber = 0
let inCommmunitySection = false
let inCommunitySection = false
let modules = []
let hasImproperFormat = false

for await (const line of rl) {
lineNumber += 1
if (line.startsWith('#### [Community]')) {
inCommmunitySection = true
inCommunitySection = true
}
if (line.startsWith('#### [Community Tools]')) {
inCommmunitySection = false
inCommunitySection = false
}
if (inCommmunitySection === false) {
if (inCommunitySection === false) {
continue
}

if (line.startsWith('- [`') !== true) {
if (line.startsWith('- [') !== true) {
continue
}

const moduleName = moduleNameRegex.exec(line)[1]
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 @@ -48,6 +58,10 @@ 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.')
}
}

function compare(current, previous) {
Expand Down

0 comments on commit af27b78

Please sign in to comment.