1
1
mirror of https://github.com/primer/css.git synced 2024-09-19 04:37:38 +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,21 +5,20 @@ 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
}
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) {
if (warning.rule === ruleName) {
console.warn(`${red('✖')} ${warning.text}`)
fail = true
}
}
}
process.exit(fail ? 1 : 0)
})
process.exit(fail ? 1 : 0)
})