在修复 sass-lint 错误 grunt 之前不要编译
Do not compile until you fix sass-lint errors grunt
我对 sass-lint 有疑问,理论上如果 SASS LINT
有错误我不应该编译 grunt
我输入错误吗?
module.exports = function (grunt) {
var path = require('path'),
argv = require('minimist')(process.argv.slice(2));
// load all grunt tasks
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-browser-sync');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-sass-lint');
/******************************************************
* PATTERN LAB CONFIGURATION
******************************************************/
//read all paths from our namespaced config file
var config = require('./patternlab-config.json'),
pl = require('patternlab-node')(config);
function paths() {
return config.paths;
}
function getConfiguredCleanOption() {
return config.cleanPublic;
}
grunt.registerTask('patternlab', 'create design systems with atomic design', function (arg) {
if (arguments.length === 0) {
pl.build(function(){}, getConfiguredCleanOption());
}
if (arg && arg === 'version') {
pl.version();
}
if (arg && arg === "patternsonly") {
pl.patternsonly(function(){},getConfiguredCleanOption());
}
if (arg && arg === "help") {
pl.help();
}
if (arg && arg === "liststarterkits") {
pl.liststarterkits();
}
if (arg && arg === "loadstarterkit") {
pl.loadstarterkit(argv.kit, argv.clean);
}
if (arg && (arg !== "version" && arg !== "patternsonly" && arg !== "help" && arg !== "liststarterkits" && arg !== "loadstarterkit")) {
pl.help();
}
});
grunt.initConfig({
/******************************************************
* COPY TASKS
******************************************************/
copy: {
main: {
files: [
{ expand: true, cwd: path.resolve(paths().source.js), src: '**/*.js', dest: path.resolve(paths().public.js) },
{ expand: true, cwd: path.resolve(paths().source.js), src: '**/*.js.map', dest: path.resolve(paths().public.js) },
{ expand: true, cwd: path.resolve(paths().source.css), src: '**/*.css', dest: path.resolve(paths().public.css) },
{ expand: true, cwd: path.resolve(paths().source.css), src: '**/*.css.map', dest: path.resolve(paths().public.css) },
{ expand: true, cwd: path.resolve(paths().source.images), src: '**/*', dest: path.resolve(paths().public.images) },
{ expand: true, cwd: path.resolve(paths().source.fonts), src: '**/*', dest: path.resolve(paths().public.fonts) },
{ expand: true, cwd: path.resolve(paths().source.root), src: 'favicon.ico', dest: path.resolve(paths().public.root) },
{ expand: true, cwd: path.resolve(paths().source.styleguide), src: ['*', '**'], dest: path.resolve(paths().public.root) },
// slightly inefficient to do this again - I am not a grunt glob master. someone fix
{ expand: true, flatten: true, cwd: path.resolve(paths().source.styleguide, 'styleguide', 'css', 'custom'), src: '*.css)', dest: path.resolve(paths().public.styleguide, 'css') }
]
}
},
/******************************************************
* SERVER AND WATCH TASKS
******************************************************/
browserSync: {
dev: {
options: {
server: path.resolve(paths().public.root),
watchTask: true,
watchOptions: {
ignoreInitial: true,
ignored: '*.html'
},
snippetOptions: {
// Ignore all HTML files within the templates folder
blacklist: ['/index.html', '/', '/?*']
},
plugins: [
{
module: 'bs-html-injector',
options: {
files: [path.resolve(paths().public.root + '/index.html'), path.resolve(paths().public.styleguide + '/styleguide.html')]
}
}
],
notify: {
styles: [
'display: none',
'padding: 15px',
'font-family: sans-serif',
'position: fixed',
'font-size: 1em',
'z-index: 9999',
'bottom: 0px',
'right: 0px',
'border-top-left-radius: 5px',
'background-color: #1B2032',
'opacity: 0.4',
'margin: 0',
'color: white',
'text-align: center'
]
}
}
}
},
bsReload: {
css: path.resolve(paths().public.root + '**/*.css')
},
sass: {
dist: {
options: {
style: 'expanded'
},
files: {
'source/css/style.css': 'source/scss/main.scss'
}
}
},
postcss: {
options: {
processors: [
require('autoprefixer')({browsers: ['last 2 version']})
]
},
dist: {
src: 'source/css/style.css'
}
},
sasslint: {
options: {
bundleExec: true,
configFile: 'sass-lint.yml',
failOnWarning: true,
failOnError: true,
colorizeOutput: true
},
target: ['source/scss/\*.scss']
},
watch: {
css: {
files: [
path.resolve(paths().source.scss + '**/*.scss'),
path.resolve(paths().source.css + '**/*.css'),
path.resolve(paths().source.styleguide + 'css/*.css'),
],
tasks: ['sass', 'sasslint', 'postcss', 'default']
},
all: {
files: [
path.resolve(paths().source.patterns + '**/*'),
path.resolve(paths().source.fonts + '/*'),
path.resolve(paths().source.images + '/*'),
path.resolve(paths().source.data + '*.json'),
path.resolve(paths().source.js + '/*.js'),
path.resolve(paths().source.root + '/*.ico'),
path.resolve(paths().source.root + '/*.mustache')
],
tasks: ['default', 'bsReload:css']
}
},
});
/******************************************************
* COMPOUND TASKS
******************************************************/
grunt.registerTask('default', ['patternlab', 'copy:main']);
grunt.registerTask('patternlab:build', ['patternlab', 'sass', 'sasslint', 'postcss', 'copy:main']);
grunt.registerTask('patternlab:watch', ['patternlab', 'sass', 'sasslint', 'postcss', 'copy:main', 'watch']);
grunt.registerTask('patternlab:serve', ['patternlab', 'sass', 'sasslint', 'postcss', 'copy:main', 'browserSync', 'watch']);
};
想法是在解决错误和警告之前不会编译
当前执行以下语句:
grunt patternlab:serve
这会生成工作环境,尽管有错误和警告
任何可能的解决方案?
将 sass lint 设置为 2 级(重要性级别),以便它在 grunt 中抛出错误,例如:
rules:
# Extends
extends-before-mixins: 2
extends-before-declarations: 2
placeholder-in-extend: 2
我对 sass-lint 有疑问,理论上如果 SASS LINT
有错误我不应该编译 grunt我输入错误吗?
module.exports = function (grunt) {
var path = require('path'),
argv = require('minimist')(process.argv.slice(2));
// load all grunt tasks
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-browser-sync');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-sass-lint');
/******************************************************
* PATTERN LAB CONFIGURATION
******************************************************/
//read all paths from our namespaced config file
var config = require('./patternlab-config.json'),
pl = require('patternlab-node')(config);
function paths() {
return config.paths;
}
function getConfiguredCleanOption() {
return config.cleanPublic;
}
grunt.registerTask('patternlab', 'create design systems with atomic design', function (arg) {
if (arguments.length === 0) {
pl.build(function(){}, getConfiguredCleanOption());
}
if (arg && arg === 'version') {
pl.version();
}
if (arg && arg === "patternsonly") {
pl.patternsonly(function(){},getConfiguredCleanOption());
}
if (arg && arg === "help") {
pl.help();
}
if (arg && arg === "liststarterkits") {
pl.liststarterkits();
}
if (arg && arg === "loadstarterkit") {
pl.loadstarterkit(argv.kit, argv.clean);
}
if (arg && (arg !== "version" && arg !== "patternsonly" && arg !== "help" && arg !== "liststarterkits" && arg !== "loadstarterkit")) {
pl.help();
}
});
grunt.initConfig({
/******************************************************
* COPY TASKS
******************************************************/
copy: {
main: {
files: [
{ expand: true, cwd: path.resolve(paths().source.js), src: '**/*.js', dest: path.resolve(paths().public.js) },
{ expand: true, cwd: path.resolve(paths().source.js), src: '**/*.js.map', dest: path.resolve(paths().public.js) },
{ expand: true, cwd: path.resolve(paths().source.css), src: '**/*.css', dest: path.resolve(paths().public.css) },
{ expand: true, cwd: path.resolve(paths().source.css), src: '**/*.css.map', dest: path.resolve(paths().public.css) },
{ expand: true, cwd: path.resolve(paths().source.images), src: '**/*', dest: path.resolve(paths().public.images) },
{ expand: true, cwd: path.resolve(paths().source.fonts), src: '**/*', dest: path.resolve(paths().public.fonts) },
{ expand: true, cwd: path.resolve(paths().source.root), src: 'favicon.ico', dest: path.resolve(paths().public.root) },
{ expand: true, cwd: path.resolve(paths().source.styleguide), src: ['*', '**'], dest: path.resolve(paths().public.root) },
// slightly inefficient to do this again - I am not a grunt glob master. someone fix
{ expand: true, flatten: true, cwd: path.resolve(paths().source.styleguide, 'styleguide', 'css', 'custom'), src: '*.css)', dest: path.resolve(paths().public.styleguide, 'css') }
]
}
},
/******************************************************
* SERVER AND WATCH TASKS
******************************************************/
browserSync: {
dev: {
options: {
server: path.resolve(paths().public.root),
watchTask: true,
watchOptions: {
ignoreInitial: true,
ignored: '*.html'
},
snippetOptions: {
// Ignore all HTML files within the templates folder
blacklist: ['/index.html', '/', '/?*']
},
plugins: [
{
module: 'bs-html-injector',
options: {
files: [path.resolve(paths().public.root + '/index.html'), path.resolve(paths().public.styleguide + '/styleguide.html')]
}
}
],
notify: {
styles: [
'display: none',
'padding: 15px',
'font-family: sans-serif',
'position: fixed',
'font-size: 1em',
'z-index: 9999',
'bottom: 0px',
'right: 0px',
'border-top-left-radius: 5px',
'background-color: #1B2032',
'opacity: 0.4',
'margin: 0',
'color: white',
'text-align: center'
]
}
}
}
},
bsReload: {
css: path.resolve(paths().public.root + '**/*.css')
},
sass: {
dist: {
options: {
style: 'expanded'
},
files: {
'source/css/style.css': 'source/scss/main.scss'
}
}
},
postcss: {
options: {
processors: [
require('autoprefixer')({browsers: ['last 2 version']})
]
},
dist: {
src: 'source/css/style.css'
}
},
sasslint: {
options: {
bundleExec: true,
configFile: 'sass-lint.yml',
failOnWarning: true,
failOnError: true,
colorizeOutput: true
},
target: ['source/scss/\*.scss']
},
watch: {
css: {
files: [
path.resolve(paths().source.scss + '**/*.scss'),
path.resolve(paths().source.css + '**/*.css'),
path.resolve(paths().source.styleguide + 'css/*.css'),
],
tasks: ['sass', 'sasslint', 'postcss', 'default']
},
all: {
files: [
path.resolve(paths().source.patterns + '**/*'),
path.resolve(paths().source.fonts + '/*'),
path.resolve(paths().source.images + '/*'),
path.resolve(paths().source.data + '*.json'),
path.resolve(paths().source.js + '/*.js'),
path.resolve(paths().source.root + '/*.ico'),
path.resolve(paths().source.root + '/*.mustache')
],
tasks: ['default', 'bsReload:css']
}
},
});
/******************************************************
* COMPOUND TASKS
******************************************************/
grunt.registerTask('default', ['patternlab', 'copy:main']);
grunt.registerTask('patternlab:build', ['patternlab', 'sass', 'sasslint', 'postcss', 'copy:main']);
grunt.registerTask('patternlab:watch', ['patternlab', 'sass', 'sasslint', 'postcss', 'copy:main', 'watch']);
grunt.registerTask('patternlab:serve', ['patternlab', 'sass', 'sasslint', 'postcss', 'copy:main', 'browserSync', 'watch']);
};
想法是在解决错误和警告之前不会编译
当前执行以下语句:
grunt patternlab:serve
这会生成工作环境,尽管有错误和警告
任何可能的解决方案?
将 sass lint 设置为 2 级(重要性级别),以便它在 grunt 中抛出错误,例如:
rules:
# Extends
extends-before-mixins: 2
extends-before-declarations: 2
placeholder-in-extend: 2