Skip to content

Commit

Permalink
Replace csslint with stylelint (atom#16803)
Browse files Browse the repository at this point in the history
  • Loading branch information
wbinnssmith authored Feb 22, 2018
1 parent 983406e commit e9d4163
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 61 deletions.
109 changes: 54 additions & 55 deletions script/lib/lint-less-paths.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,63 @@
'use strict'

const csslint = require('csslint').CSSLint
const expandGlobPaths = require('./expand-glob-paths')
const LessCache = require('less-cache')
const stylelint = require('stylelint')
const path = require('path')
const readFiles = require('./read-files')

const CONFIG = require('../config')
const LESS_CACHE_VERSION = require('less-cache/package.json').version

module.exports = function () {
const globPathsToLint = [
path.join(CONFIG.repositoryRootPath, 'static/**/*.less')
]
const lintOptions = {
'adjoining-classes': false,
'duplicate-background-images': false,
'box-model': false,
'box-sizing': false,
'bulletproof-font-face': false,
'compatible-vendor-prefixes': false,
'display-property-grouping': false,
'duplicate-properties': false,
'fallback-colors': false,
'font-sizes': false,
'gradients': false,
'ids': false,
'important': false,
'known-properties': false,
'order-alphabetical': false,
'outline-none': false,
'overqualified-elements': false,
'regex-selectors': false,
'qualified-headings': false,
'unique-headings': false,
'universal-selector': false,
'vendor-prefix': false
}
for (let rule of csslint.getRules()) {
if (!lintOptions.hasOwnProperty(rule.id)) lintOptions[rule.id] = true
}
const lessCache = new LessCache({
cacheDir: path.join(CONFIG.intermediateAppPath, 'less-compile-cache'),
fallbackDir: path.join(CONFIG.atomHomeDirPath, 'compile-cache', 'prebuild-less', LESS_CACHE_VERSION),
syncCaches: true,
resourcePath: CONFIG.repositoryRootPath,
importPaths: [
path.join(CONFIG.intermediateAppPath, 'static', 'variables'),
path.join(CONFIG.intermediateAppPath, 'static')
]
})
return expandGlobPaths(globPathsToLint).then(readFiles).then((files) => {
const errors = []
for (let file of files) {
const css = lessCache.cssForFile(file.path, file.content)
const result = csslint.verify(css, lintOptions)
for (let message of result.messages) {
errors.push({path: file.path.replace(/\.less$/, '.css'), lineNumber: message.line, message: message.message, rule: message.rule.id})
return stylelint
.lint({
files: path.join(CONFIG.repositoryRootPath, 'static/**/*.less'),
configBasedir: __dirname,
configFile: path.resolve(__dirname, '..', '..', 'stylelint.config.js')
})
.then(({results}) => {
const errors = []

for (const result of results) {
for (const deprecation of result.deprecations) {
console.log('stylelint encountered deprecation:', deprecation.text)
if (deprecation.reference != null) {
console.log('more information at', deprecation.reference)
}
}

for (const invalidOptionWarning of result.invalidOptionWarnings) {
console.warn(
'stylelint encountered invalid option:',
invalidOptionWarning.text
)
}

if (result.errored) {
for (const warning of result.warnings) {
if (warning.severity === 'error') {
errors.push({
path: result.source,
lineNumber: warning.line,
message: warning.text,
rule: warning.rule
})
} else {
console.warn(
'stylelint encountered non-critical warning in file',
result.source,
'at line',
warning.line,
'for rule',
warning.rule + ':',
warning.text
)
}
}
}
}
}
return errors
})

return errors
})
.catch(err => {
console.error('There was a problem linting LESS:')
throw err
})
}
3 changes: 2 additions & 1 deletion script/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"babel-core": "5.8.38",
"coffeelint": "1.15.7",
"colors": "1.1.2",
"csslint": "1.0.2",
"donna": "1.0.16",
"electron-chromedriver": "~1.7",
"electron-link": "0.1.2",
Expand All @@ -31,6 +30,8 @@
"season": "5.3.0",
"semver": "5.3.0",
"standard": "8.4.0",
"stylelint": "^9.0.0",
"stylelint-config-standard": "^18.1.0",
"sync-request": "3.0.1",
"tello": "1.0.7",
"webdriverio": "2.4.5",
Expand Down
2 changes: 1 addition & 1 deletion static/cursors.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@ibeam-2x: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAQAAADZc7J/AAAAz0lEQVRIx2NgYGBY/R8I/vx5eelX3n82IJ9FxGf6tksvf/8FiTMQAcAGQMDvSwu09abffY8QYSAScNk45G198eX//yev73/4///701eh//kZSARckrNBRvz//+8+6ZohwCzjGNjdgQxkAg7B9WADeBjIBqtJCbhRA0YNoIkBSNmaPEMoNmA0FkYNoFKhapJ6FGyAH3nauaSmPfwI0v/3OukVi0CIZ+F25KrtYcx/CTIy0e+rC7R1Z4KMICVTQQ14feVXIbR695u14+Ir4gwAAD49E54wc1kWAAAAAElFTkSuQmCC');

.cursor-white() {
cursor: -webkit-image-set(@ibeam-1x 1x, @ibeam-2x 2x) 5 8, text;
cursor: -webkit-image-set(@ibeam-1x 1dppx, @ibeam-2x 2dppx) 5 8, text;
}

// Editors
Expand Down
14 changes: 10 additions & 4 deletions static/docks.less
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,16 @@ atom-dock {
// Promote to own layer, fixes rendering issue atom/atom#14915
will-change: transform;

&.right { left: 0; }
&.bottom { top: 0; }
&.left { right: 0; }
}
&.right {
left: 0;
}
&.bottom {
top: 0;
}
&.left {
right: 0;
}
}

// Hide the button.
&:not(.atom-dock-toggle-button-visible) {
Expand Down
23 changes: 23 additions & 0 deletions stylelint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const path = require('path');

module.exports = {
"extends": "stylelint-config-standard",
"ignoreFiles": [path.resolve(__dirname, "static", "atom.less")],
"rules": {
"color-hex-case": null, // TODO: enable?
"max-empty-lines": null, // TODO: enable?
"selector-type-no-unknown": null,
"function-comma-space-after": null, // TODO: enable?
"font-family-no-missing-generic-family-keyword": null, // needed for octicons (no sensible fallback)
"declaration-empty-line-before": null, // TODO: enable?
"declaration-block-trailing-semicolon": null, // TODO: enable
"no-descending-specificity": null,
"number-leading-zero": null, // TODO: enable?
"no-duplicate-selectors": null,
"selector-pseudo-element-colon-notation": null, // TODO: enable?
"selector-list-comma-newline-after": null, // TODO: enable?
"rule-empty-line-before": null, // TODO: enable?
"at-rule-empty-line-before": null, // TODO: enable?
"font-family-no-duplicate-names": null, // TODO: enable?
}
}

0 comments on commit e9d4163

Please sign in to comment.