lint-less-paths.js
1 'use strict'; 2 3 const stylelint = require('stylelint'); 4 const path = require('path'); 5 6 const CONFIG = require('../config'); 7 8 module.exports = function() { 9 return stylelint 10 .lint({ 11 files: path.join(CONFIG.repositoryRootPath, 'static/**/*.less'), 12 configBasedir: __dirname, 13 configFile: path.resolve(__dirname, '..', '..', 'stylelint.config.js') 14 }) 15 .then(({ results }) => { 16 const errors = []; 17 18 for (const result of results) { 19 for (const deprecation of result.deprecations) { 20 console.log('stylelint encountered deprecation:', deprecation.text); 21 if (deprecation.reference != null) { 22 console.log('more information at', deprecation.reference); 23 } 24 } 25 26 for (const invalidOptionWarning of result.invalidOptionWarnings) { 27 console.warn( 28 'stylelint encountered invalid option:', 29 invalidOptionWarning.text 30 ); 31 } 32 33 if (result.errored) { 34 for (const warning of result.warnings) { 35 if (warning.severity === 'error') { 36 errors.push({ 37 path: result.source, 38 lineNumber: warning.line, 39 message: warning.text, 40 rule: warning.rule 41 }); 42 } else { 43 console.warn( 44 'stylelint encountered non-critical warning in file', 45 result.source, 46 'at line', 47 warning.line, 48 'for rule', 49 warning.rule + ':', 50 warning.text 51 ); 52 } 53 } 54 } 55 } 56 57 return errors; 58 }) 59 .catch(err => { 60 console.error('There was a problem linting LESS:'); 61 throw err; 62 }); 63 };