Skip to content

Commit

Permalink
Drop Node < 6
Browse files Browse the repository at this point in the history
- Drop it from CI jobs
- Use a bunch of ES6 features
- Update docs
  • Loading branch information
jwilsson committed Feb 20, 2018
1 parent 1ef433a commit 65ad429
Show file tree
Hide file tree
Showing 79 changed files with 110 additions and 123 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ node_js:
- "8"
- "7"
- "6"
- "5"
- "4"

before_script:
- node --version
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* [Developer resources](#developer-resources)

## Installation
_[Node.js](https://nodejs.org/) 4 (or later) is required._
_[Node.js](https://nodejs.org/) 6 (or later) is required._

Run the following from the command line to install `lesshint` (add `-g` to install globally):

Expand Down
2 changes: 0 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ environment:
- nodejs_version: "8"
- nodejs_version: "7"
- nodejs_version: "6"
- nodejs_version: "5"
- nodejs_version: "4"

install:
- ps: Install-Product node $env:nodejs_version
Expand Down
2 changes: 1 addition & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const Runner = require('./runner');

module.exports = function (program) {
module.exports = (program) => {
const runner = new Runner(program);

return runner.run();
Expand Down
6 changes: 2 additions & 4 deletions lib/config-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const stripJsonComments = require('strip-json-comments');
const RcFinder = require('rcfinder');
const fs = require('fs');

const loadConfig = function (path) {
const loadConfig = (path) => {
let data = fs.readFileSync(path, 'utf8');

data = stripJsonComments(data);
Expand All @@ -19,9 +19,7 @@ const loadConfig = function (path) {
});
};

module.exports = function (path) {
path = path || process.cwd();

module.exports = (path = process.cwd()) => {
const stats = fs.statSync(path);
let config;

Expand Down
14 changes: 6 additions & 8 deletions lib/lesshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,9 @@ class Lesshint {
});
}

checkString (input, checkPath) {
checkString (input, checkPath = '') {
let result;

checkPath = checkPath || '';

try {
const linter = new Linter(input, checkPath, this.config);

Expand Down Expand Up @@ -163,11 +161,11 @@ class Lesshint {
}

// Make sure there is a leading dot
const fileExtensions = this.config.fileExtensions.map(function (extension) {
const fileExtensions = this.config.fileExtensions.map((extension) => {
return '.' + extension.replace(/^\./, '');
});

return fileExtensions.indexOf(path.extname(file)) !== -1;
return fileExtensions.includes(path.extname(file));
}

formatResults (files, resolve, reject) {
Expand All @@ -185,7 +183,7 @@ class Lesshint {
}

isExcluded (checkPath) {
return this.config.excludedFiles.some(function (pattern) {
return this.config.excludedFiles.some((pattern) => {
return minimatch(checkPath, pattern, {
matchBase: true
});
Expand All @@ -198,9 +196,9 @@ class Lesshint {
return config;
}

getReporter (reporter) {
getReporter (reporter = 'default') {
// Nothing defined, just fall back to our simple default
if (!reporter || reporter === 'default') {
if (reporter === 'default') {
const reporterPath = path.resolve(__dirname, './reporters/default');

return require(reporterPath);
Expand Down
16 changes: 7 additions & 9 deletions lib/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Linter {
}

// Node type(s) not applicable, bail
if (Array.isArray(linter.nodeTypes) && linter.nodeTypes.indexOf(node.type) === -1) {
if (Array.isArray(linter.nodeTypes) && !linter.nodeTypes.includes(node.type)) {
return;
}

Expand Down Expand Up @@ -124,10 +124,10 @@ class Linter {
* to the collection
*/
piece = merge({
column: column,
column,
file: this.filename,
fullPath: this.fullPath,
line: line,
line,
linter: linter.name,
message: `'Unknown linting error. Source: ${ linter.name }`,
position: column + this.linesRaw.slice(0, line - 1).join('').length - 1,
Expand Down Expand Up @@ -263,7 +263,7 @@ class Linter {
column: comment.source.start.column,
file: this.filename,
fullPath: this.fullPath,
line: line,
line,
linter: 'parse error',
message: `Invalid inline configuration comment: "${ text }"`,
severity: 'error'
Expand All @@ -273,14 +273,12 @@ class Linter {
}

// Old, deprecated way of handling inline configuration comments
getInlineOptions (node) {
node = node || {};

getInlineOptions (node = {}) {
if (node.type !== 'comment') {
return {};
}

const start = node.source.start;
const { start } = node.source;

// Not the first thing in the file, bail
if (start.line !== 1 && start.column !== 1) {
Expand Down Expand Up @@ -334,7 +332,7 @@ class Linter {
}

// If it's only shorthand enabled or disabled, account for that
Object.keys(rules).forEach(function (rule) {
Object.keys(rules).forEach((rule) => {
if (typeof rules[rule] === 'boolean') {
rules[rule] = {
enabled: rules[rule]
Expand Down
2 changes: 1 addition & 1 deletion lib/linters/attribute_quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
+ selector.attribute.length + selector.operator.length;

results.push({
column: column,
column,
line: node.source.start.line + selector.source.start.line - 1,
message: this.message
});
Expand Down
6 changes: 3 additions & 3 deletions lib/linters/border_zero.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ module.exports = {
const properties = ['border', 'border-bottom', 'border-left', 'border-right', 'border-top'];

// Not a border* property, bail
if (properties.indexOf(node.prop) === -1) {
if (!properties.includes(node.prop)) {
return;
}

const value = node.value;
const { value } = node;

// Bail if it's an actual border
if (value !== '0' && value !== 'none') {
Expand Down Expand Up @@ -50,7 +50,7 @@ module.exports = {
return [{
column: position.column,
line: position.line,
message: message
message
}];
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/linters/duplicate_property.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
return true;
}

if (!decl.prop.match(/\+_?$/) && properties.indexOf(decl.prop) >= 0) {
if (!decl.prop.match(/\+_?$/) && properties.includes(decl.prop)) {
results.push({
message: util.format(this.message, decl.prop),
column: decl.source.start.column,
Expand All @@ -33,7 +33,7 @@ module.exports = {
* contains the property name, for debugging purposes. It doesn't
* hurt anything.
*/
if (!config.exclude || config.exclude.indexOf(decl.prop) < 0) {
if (!config.exclude || !config.exclude.includes(decl.prop)) {
properties.push(decl.prop);
}
});
Expand Down
4 changes: 2 additions & 2 deletions lib/linters/empty_rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module.exports = {
let hasDeclarations = false;

const nodeTypes = ['atrule', 'decl', 'import'];
node.walk(function (child) {
if (nodeTypes.indexOf(child.type) !== -1 || (child.type === 'rule' && child.empty)) {
node.walk((child) => {
if (nodeTypes.includes(child.type) || (child.type === 'rule' && child.empty)) {
hasDeclarations = true;

return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/linters/id_selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {

tree.each((selector) => {
selector.walkIds((id) => {
if (excludes.indexOf(id.value) !== -1) {
if (excludes.includes(id.value)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/linters/import_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
const file = value.value.trim().replace(/['"]/g, '');

// Exit if the path is a absolute URL or excluded
if (isAbsoluteURL(file) || config.exclude.indexOf(file) !== -1) {
if (isAbsoluteURL(file) || config.exclude.includes(file)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/linters/newline_after_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
message: 'All blocks should be followed by a new line.',

lint: function newlineAfterBlockLinter (config, node) {
const parent = node.parent;
const { parent } = node;

let prev = parent.index(node) - 1;
prev = parent.nodes[prev] || {};
Expand Down
8 changes: 4 additions & 4 deletions lib/linters/property_units.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ module.exports = {
return;
}

const unit = value.unit;
const { unit } = value;

// If this unit is marked invalid, then the other checks are moot
if (config.invalid.indexOf(unit) === -1) {
if (!config.invalid.includes(unit)) {
// Check if the unit is allowed for this property
if (Array.isArray(allowed) && allowed.indexOf(unit) !== -1) {
if (Array.isArray(allowed) && allowed.includes(unit)) {
return;
}

// Unit allowed, bail
if (!allowed && config.valid.indexOf(unit) !== -1) {
if (!allowed && config.valid.includes(unit)) {
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/linters/qualifying_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
message: '%s selectors should not include a qualifying element.',

inspectParent: function (node) {
const parent = node.parent;
const { parent } = node;
const result = {
startsWith: '',
endsWith: '',
Expand Down Expand Up @@ -50,7 +50,7 @@ module.exports = {
let result;

selector.nodes.forEach((element, index) => {
if (selectorTypes.indexOf(element.type) === -1) {
if (!selectorTypes.includes(element.type)) {
return;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/linters/selector_naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ module.exports = {
const results = [];

selectors.walk((selector) => {
if (selectorTypes.indexOf(selector.type) === -1) {
if (!selectorTypes.includes(selector.type)) {
return;
}

const name = selector.value;

if (exclude.indexOf(name) !== -1) {
if (exclude.includes(name)) {
return;
}

if (
(config.disallowUppercase && name.toLowerCase() !== name) ||
(config.disallowUnderscore && name.indexOf('_') !== -1) ||
(config.disallowDash && name.indexOf('-') !== -1)
(config.disallowUnderscore && name.includes('_')) ||
(config.disallowDash && name.includes('-'))
) {
const position = node.positionBy({
word: selector.toString().trim()
Expand Down
4 changes: 2 additions & 2 deletions lib/linters/single_line_per_property.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const hasNewline = require('../utils/has-newline');

const isValidAfter = function (node, index) {
const isValidAfter = (node, index) => {
const next = node.parent.nodes[index + 1];

// Nothing after, valid
Expand Down Expand Up @@ -40,7 +40,7 @@ module.exports = {
const results = [];

node.nodes.forEach((child, index) => {
if (types.indexOf(child.type) === -1) {
if (!types.includes(child.type)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/linters/single_line_per_selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
selectors.each((selector) => {
selector.each((child) => {
const value = child.toString().trim();
const length = value.length;
const { length } = value;

if (length > longest) {
longest = length;
Expand Down
2 changes: 1 addition & 1 deletion lib/linters/space_around_bang.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = {
return [{
column: position.column,
line: position.line,
message: message
message
}];
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/linters/space_around_comma.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
message: 'Commas should%s be %s by %s space.',

lint: function spaceAroundCommaLinter (config, node) {
let column = node.source.start.column;
let { column } = node.source.start;
let value;

if (node.params) {
Expand Down Expand Up @@ -100,7 +100,7 @@ module.exports = {
if (message) {
results.push({
column: column + child.source.start.column - ','.length,
message: message
message
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/linters/space_around_operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = {
results.push({
column: position.column,
line: position.line,
message: message
message
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/linters/space_between_parens.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
},

lint: function spaceBetweenParensLinter (config, node) {
let column = node.source.start.column;
let { column } = node.source.start;
let value;

if (node.params) {
Expand Down
Loading

0 comments on commit 65ad429

Please sign in to comment.