1
1
mirror of https://github.com/primer/css.git synced 2024-12-29 09:06:07 +03:00

Merge pull request #946 from primer/test-todos

Add TODO@version stylelint rule (local)
This commit is contained in:
Shawn Allen 2019-10-23 09:32:34 -07:00 committed by GitHub
commit 7df15de7b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 1 deletions

38
lib/stylelint-todo.js Normal file
View File

@ -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
})
}
}
})
}
})

View File

@ -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'}]
}
}