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

Add TODO@version stylelint rule (local) #946

Merged
merged 3 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions lib/stylelint-todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const semver = require('semver')
const stylelint = require('stylelint')

const ruleName = 'primer-css/TODO'
const pattern = /\bTODO@([^:]+):\s+(.+)$/

const messages = stylelint.utils.ruleMessages(ruleName, {
rejected: message => message
})

module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}) => {
const {currentVersion} = options
if (!currentVersion) {
// eslint-disable-next-line no-console
console.warn(`No "currentVersion" supplied to ${ruleName}; bailing`)
return () => null
}

let match
return (root, result) => {
root.walkComments(node => {
if ((match = node.text.match(pattern))) {
// eslint-disable-next-line no-unused-vars
const [substr, todoVersion, message] = match
if (semver.lte(todoVersion, currentVersion)) {
stylelint.utils.report({
message: messages.rejected(
`Unresolved TODO comment: "${message}" (expected to be resolved in "${todoVersion}")`
),
node,
result,
ruleName
})
}
}
})
}
})
6 changes: 5 additions & 1 deletion stylelint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const currentVersion = process.env.PRIMER_VERSION || require('./package.json').version

module.exports = {
extends: ['stylelint-config-primer'],
plugins: ['./lib/stylelint-todo'],
syntax: 'scss',
rules: {
'primer/no-override': false
'primer/no-override': false,
'primer-css/TODO': [true, {currentVersion, severity: 'error'}]
}
}