-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
200 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = function ($) { | ||
const errors = []; | ||
let allButtonsHaveType = true; | ||
|
||
$('button').each(function (index, el) { | ||
const $el = $(el); | ||
|
||
if (!$el.attr('type')) { | ||
allButtonsHaveType = false; | ||
} | ||
}); | ||
|
||
if (!allButtonsHaveType) { | ||
errors.push('Buttons need a `type` attribute.'); | ||
} | ||
|
||
return errors; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const glob = require('glob'); | ||
const pug = require('pug'); | ||
const cheerio = require('cheerio'); | ||
const chalk = require('chalk'); | ||
|
||
const locals = require('../templates/locals'); | ||
const paths = require('../paths'); | ||
|
||
const allComponentPaths = glob.sync(paths.content.templates.allComponents); | ||
const linterPaths = glob.sync(paths.content.linter.tests); | ||
|
||
module.exports = function (done) { | ||
console.log('Running linters on Pug templates within components...\n'); | ||
|
||
allComponentPaths.forEach(function (templatePath) { | ||
|
||
const fakeIcon = 'include ../../../../core/templates/mixins/icon\n' | ||
|
||
const pugContent = fakeIcon + fs.readFileSync(templatePath, 'utf8'); | ||
|
||
const compiledHtml = pug.compile(pugContent, { | ||
pretty: true, | ||
basedir: '/content', | ||
filename: templatePath | ||
})(locals.getDefaultLocals()); | ||
|
||
const $ = cheerio.load(compiledHtml); | ||
|
||
linterPaths.forEach(function (linterPath) { | ||
const linter = require(path.join('../../', linterPath)); | ||
|
||
const linterResult = linter($); | ||
|
||
if (linterResult && linterResult.length > 0) { | ||
console.log(chalk.underline.bold(templatePath)); | ||
|
||
linterResult.forEach(function (result) { | ||
console.log('\t' + chalk.red(result)); | ||
}); | ||
|
||
console.log('\n'); | ||
} | ||
}); | ||
}); | ||
|
||
console.log('Done linting Pug files!'); | ||
done(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters