New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setup linter for HTML #5195
Setup linter for HTML #5195
Changes from 5 commits
3ff10ac
13cd5b0
fddb06f
6f821d7
83822eb
fd5232a
7cfcf5a
1b591b1
9f130a2
c640e69
098c133
71792f1
70822cf
f8f119a
8183537
0171194
f588414
599fd09
c3c0bea
066b3ae
31d6571
0940fdd
8378328
adbfb4d
27fa1a7
6f96837
9d2d092
8ac4864
ccd9cab
1fc07d2
8e4c315
4675e85
9b59b55
9bb89f4
3746bad
261085f
1474880
57fc01c
4a2ff8c
03321b0
58db09d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ extends: chartjs | |
env: | ||
browser: true | ||
node: true | ||
|
||
plugins: ['html'] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
'rules': { | ||
//'indent-style': 'tabs', | ||
//'indent-width': 1, | ||
'indent-style': false, | ||
'indent-width': 2, | ||
'attr-quote-style': 'double', | ||
'spec-char-escape': false, | ||
'attr-bans': ['align', 'background', 'bgcolor', 'border', 'frameborder', 'longdesc', 'marginwidth', 'marginheight', 'scrolling', 'syle'/*, 'width'*/], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is a typo to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took the default option and commented the attributes triggering errors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, then you can remove the 2 last values ( |
||
'tag-bans': [/*'style', */'b', 'i'], | ||
'id-class-style': false, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,17 +20,26 @@ var collapse = require('bundle-collapser/plugin'); | |
var yargs = require('yargs'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var htmllint = require('gulp-htmllint'); | ||
var package = require('./package.json'); | ||
var htmllintOptions = require('./.htmllintrc.js'); | ||
|
||
var argv = yargs | ||
.option('force-output', {default: false}) | ||
.option('lint-script-elements', {default: false}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we decide to lint our samples, then it should be part of the regular linting process. That why I would not add this |
||
.option('silent-errors', {default: false}) | ||
.option('verbose', {default: false}) | ||
.argv | ||
|
||
var srcDir = './src/'; | ||
var outDir = './dist/'; | ||
|
||
var htmlFiles = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is equivalent to |
||
'./samples/*.html', | ||
'./samples/*/*.html', | ||
'./samples/*/*/*.html', | ||
]; | ||
|
||
var header = "/*!\n" + | ||
" * Chart.js\n" + | ||
" * http://chartjs.org/\n" + | ||
|
@@ -50,8 +59,9 @@ gulp.task('build', buildTask); | |
gulp.task('package', packageTask); | ||
gulp.task('watch', watchTask); | ||
gulp.task('lint', lintTask); | ||
gulp.task('lint-html', lintHtmlTask); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This task should be ran as a dependency of the |
||
gulp.task('docs', docsTask); | ||
gulp.task('test', ['lint', 'validHTML', 'unittest']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also remove the |
||
gulp.task('test', ['lint', 'lint-html', 'validHTML', 'unittest']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think htmllint do the same job as |
||
gulp.task('size', ['library-size', 'module-sizes']); | ||
gulp.task('server', serverTask); | ||
gulp.task('validHTML', validHTMLTask); | ||
|
@@ -159,6 +169,9 @@ function lintTask() { | |
'src/**/*.js', | ||
'test/**/*.js' | ||
]; | ||
if (argv.lintScriptElements) { | ||
files = files.concat(htmlFiles); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per my previous comment: var files = [
'samples/**/*.html',
'samples/**/*.js',
'src/**/*.js',
'test/**/*.js'
]; |
||
} | ||
|
||
// NOTE(SB) codeclimate has 'complexity' and 'max-statements' eslint rules way too strict | ||
// compare to what the current codebase can support, and since it's not straightforward | ||
|
@@ -176,6 +189,11 @@ function lintTask() { | |
.pipe(eslint.failAfterError()); | ||
} | ||
|
||
function lintHtmlTask() { | ||
return gulp.src(htmlFiles) | ||
.pipe(htmllint(htmllintOptions)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to require .pipe(htmllint({
config: '.htmllint.js' // or .yml if supported
})); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the source, gulp-htmllint only supports proper JSON |
||
} | ||
|
||
function docsTask(done) { | ||
const script = require.resolve('gitbook-cli/bin/gitbook.js'); | ||
const cmd = process.execPath; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,15 @@ | |
"coveralls": "^3.0.0", | ||
"eslint": "^4.9.0", | ||
"eslint-config-chartjs": "^0.1.0", | ||
"eslint-plugin-html": "^4.0.2", | ||
"gitbook-cli": "^2.3.2", | ||
"gulp": "3.9.x", | ||
"gulp-concat": "~2.6.x", | ||
"gulp-connect": "~5.0.0", | ||
"gulp-eslint": "^4.0.0", | ||
"gulp-file": "^0.3.0", | ||
"gulp-html-validator": "^0.0.5", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be removed (see previous comment) |
||
"gulp-htmllint": "0.0.15", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"gulp-insert": "~0.5.0", | ||
"gulp-replace": "^0.6.1", | ||
"gulp-size": "~2.1.0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,4 +93,4 @@ | |
</script> | ||
</body> | ||
|
||
</html> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does htmllint support YAML config? It's usually more readable and easy to manipulate but also consistent with our other config files.