1
1
mirror of https://github.com/primer/css.git synced 2024-11-30 01:04:04 +03:00

chore: lint

This commit is contained in:
Shawn Allen 2019-10-14 16:31:51 -07:00
parent 08fe118c75
commit ceb67a351c
2 changed files with 19 additions and 16 deletions

View File

@ -11,6 +11,7 @@ const messages = stylelint.utils.ruleMessages(ruleName, {
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
}
@ -19,10 +20,13 @@ module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}) => {
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}")`),
message: messages.rejected(
`Unresolved TODO comment: "${message}" (expected to be resolved in "${todoVersion}")`
),
node,
result,
ruleName

View File

@ -5,12 +5,11 @@ const {red} = require('colorette')
const ruleName = 'primer-css/TODO'
const cwd = process.cwd()
stylelint
.lint({files: 'src/**/*.scss'})
.then(data => {
stylelint.lint({files: 'src/**/*.scss'}).then(data => {
let fail = false
for (const {source, warnings} of data.results) {
if (warnings.some(w => w.rule === ruleName)) {
// eslint-disable-next-line prefer-template
console.warn('\n' + source.substr(cwd.length + 1))
}
for (const warning of warnings) {
@ -22,4 +21,4 @@ stylelint
}
process.exit(fail ? 1 : 0)
})
})