mirror of
https://github.com/primer/css.git
synced 2024-11-30 01:04:04 +03:00
add TODO(version) tests
This commit is contained in:
parent
cac447a3ee
commit
08fe118c75
34
lib/stylelint-todo.js
Normal file
34
lib/stylelint-todo.js
Normal file
@ -0,0 +1,34 @@
|
||||
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) {
|
||||
console.warn(`No "currentVersion" supplied to ${ruleName}; bailing`)
|
||||
return () => null
|
||||
}
|
||||
|
||||
let match
|
||||
return (root, result) => {
|
||||
root.walkComments(node => {
|
||||
if ((match = node.text.match(pattern))) {
|
||||
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
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
25
script/test-todos.js
Executable file
25
script/test-todos.js
Executable file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env node
|
||||
const stylelint = require('stylelint')
|
||||
const {red} = require('colorette')
|
||||
|
||||
const ruleName = 'primer-css/TODO'
|
||||
const cwd = process.cwd()
|
||||
|
||||
stylelint
|
||||
.lint({files: 'src/**/*.scss'})
|
||||
.then(data => {
|
||||
let fail = false
|
||||
for (const {source, warnings} of data.results) {
|
||||
if (warnings.some(w => w.rule === ruleName)) {
|
||||
console.warn('\n' + source.substr(cwd.length + 1))
|
||||
}
|
||||
for (const warning of warnings) {
|
||||
if (warning.rule === ruleName) {
|
||||
console.warn(`${red('✖')} ${warning.text}`)
|
||||
fail = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
process.exit(fail ? 1 : 0)
|
||||
})
|
@ -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'}]
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user