Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Assorted lint tweaks #2903

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,11 @@
"globals": {},
"extends": "eslint:recommended",
"rules": {
"no-bitwise": 2,
"block-scoped-var": 2,
"camelcase": 0,
"curly": 2,
"eol-last": 2,
"eqeqeq": 2,
"no-unused-expressions": [
2,
{
"allowTernary": true
}
],
"wrap-iife": [
2,
"any"
],
"indent": [
2,
2,
Expand All @@ -27,20 +18,39 @@
}
],
"linebreak-style": 2,
"no-multi-str": 2,
"new-cap": 2,
"no-bitwise": 2,
"no-caller": 2,
"no-console": 0,
"no-else-return": 2,
"no-extra-semi": 2,
"no-lonely-if": 2,
"no-multi-str": 2,
"no-prototype-builtins": 2,
"no-redeclare": 2,
"no-undef": 2,
"no-unused-expressions": [
2,
{
"allowTernary": true
}
],
"no-unused-vars": 2,
"no-useless-escape": 2,
"quotes": [
2,
"single"
],
"strict": 0,
"no-undef": 2,
"no-unused-vars": 2,
"semi": 2,
"no-extra-semi": 2,
"no-redeclare": 2,
"block-scoped-var": 2,
"no-console": 0
"space-before-function-paren": [
2,
"never"
],
"strict": 0,
"wrap-iife": [
2,
"any"
],
"yoda": 2
}
}
25 changes: 12 additions & 13 deletions bin/node-sass
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,13 @@ function getOptions(args, options) {
options.sourceMap = options.dest + '.map';
} else if (!sourceMapIsDirectory) {
options.sourceMap = path.resolve(options.sourceMapOriginal);
} else if (sourceMapIsDirectory) {
if (!options.directory) {
options.sourceMap = path.resolve(options.sourceMapOriginal, path.basename(options.dest) + '.map');
} else {
sassDir = path.resolve(options.directory);
file = path.relative(sassDir, args[0]);
mapDir = path.resolve(options.sourceMapOriginal);
options.sourceMap = path.join(mapDir, file).replace(path.extname(file), '.css.map');
}
} else if (!options.directory) {
options.sourceMap = path.resolve(options.sourceMapOriginal, path.basename(options.dest) + '.map');
} else {
sassDir = path.resolve(options.directory);
file = path.relative(sassDir, args[0]);
mapDir = path.resolve(options.sourceMapOriginal);
options.sourceMap = path.join(mapDir, file).replace(path.extname(file), '.css.map');
}
}

Expand All @@ -238,7 +236,7 @@ function watch(options, emitter) {
var handler = function(files) {
files.added.forEach(function(file) {
var watch = gaze.watched();
Object.keys(watch).forEach(function (dir) {
Object.keys(watch).forEach(function(dir) {
if (watch[dir].indexOf(file) !== -1) {
gaze.add(file);
}
Expand Down Expand Up @@ -300,15 +298,15 @@ function run(options, emitter) {
}

if (options.importer) {
if ((path.resolve(options.importer) === path.normalize(options.importer).replace(/(.+)([\/|\\])$/, '$1'))) {
if ((path.resolve(options.importer) === path.normalize(options.importer).replace(/(.+)([/|\\])$/, '$1'))) {
options.importer = require(options.importer);
} else {
options.importer = require(path.resolve(options.importer));
}
}

if (options.functions) {
if ((path.resolve(options.functions) === path.normalize(options.functions).replace(/(.+)([\/|\\])$/, '$1'))) {
if ((path.resolve(options.functions) === path.normalize(options.functions).replace(/(.+)([/|\\])$/, '$1'))) {
options.functions = require(options.functions);
} else {
options.functions = require(path.resolve(options.functions));
Expand Down Expand Up @@ -352,7 +350,8 @@ function renderDir(options, emitter) {
glob(globPath, { ignore: '**/_*', follow: options.follow }, function(err, files) {
if (err) {
return emitter.emit('error', util.format('You do not have permission to access this path: %s.', err.path));
} else if (!files.length) {
}
if (!files.length) {
return emitter.emit('error', 'No input file was found.');
}

Expand Down
6 changes: 3 additions & 3 deletions lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ function getInstalledBinaries() {
*/
function isSupportedEnvironment(platform, arch, abi) {
return (
false !== getHumanPlatform(platform) &&
false !== getHumanArchitecture(arch) &&
false !== getHumanNodeVersion(abi)
getHumanPlatform(platform) !== false &&
getHumanArchitecture(arch) !== false &&
getHumanNodeVersion(abi) !== false
);
}

Expand Down
12 changes: 6 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function getLinefeed(options) {
function buildIncludePaths(options) {
options.includePaths = options.includePaths || [];

if (process.env.hasOwnProperty('SASS_PATH')) {
if (Object.prototype.hasOwnProperty.call(process.env, 'SASS_PATH')) {
options.includePaths = options.includePaths.concat(
process.env.SASS_PATH.split(path.delimiter)
);
Expand All @@ -188,12 +188,12 @@ function buildIncludePaths(options) {

function getOptions(opts, cb) {
if (typeof opts !== 'object') {
throw new Error('Invalid: options is not an object.');
throw new TypeError('Invalid: options is not an object.');
}
var options = clonedeep(opts || {});

options.sourceComments = options.sourceComments || false;
if (options.hasOwnProperty('file')) {
if (Object.prototype.hasOwnProperty.call(options, 'file')) {
options.file = getInputFile(options);
}
options.outFile = getOutputFile(options);
Expand Down Expand Up @@ -229,11 +229,11 @@ function tryCallback(callback, args) {
} catch (e) {
if (typeof e === 'string') {
return new binding.types.Error(e);
} else if (e instanceof Error) {
}
if (e instanceof Error) {
return new binding.types.Error(e.message);
} else {
return new binding.types.Error('An unexpected error occurred');
}
return new binding.types.Error('An unexpected error occurred');
}
}

Expand Down
5 changes: 2 additions & 3 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var chalk = require('chalk'),
fs = require('fs'),
mkdirp = require('mkdirp'),
path = require('path'),
sass = require('./');
sass = require('.');

/**
* Render
Expand Down Expand Up @@ -111,8 +111,7 @@ module.exports = function(options, emitter) {
var renderCallback = function(err, result) {
if (err) {
error(err);
}
else {
} else {
success(result);
}
};
Expand Down
10 changes: 6 additions & 4 deletions memory-tests/_measure.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"use strict";
'use strict';

module.exports = function iterateAndMeasure(fn, mod = 1000000) {
let count = 0;
module.exports = function iterateAndMeasure(fn, mod) {
mod = mod || 1000000;
var count = 0;
// eslint-disable-next-line no-constant-condition
while (true) {
count++;
fn();
if (count % mod === 0) {
console.log(process.memoryUsage().rss / 1000000);
}
}
}
};
2 changes: 1 addition & 1 deletion memory-tests/boolean.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var types = require('../').types;
var types = require('..').types;
var iterateAndMeasure = require('./_measure');

iterateAndMeasure(function() { return types.Boolean(true).getValue(); });
4 changes: 2 additions & 2 deletions memory-tests/function-bridge.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
'use strict';

var sass = require("../");
var sass = require('..');
var iterateAndMeasure = require('./_measure');

iterateAndMeasure(function() {
Expand Down
2 changes: 1 addition & 1 deletion memory-tests/map.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var types = require('../').types;
var types = require('..').types;
var iterateAndMeasure = require('./_measure');

iterateAndMeasure(function() {
Expand Down
2 changes: 1 addition & 1 deletion memory-tests/string.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var types = require('../').types;
var types = require('..').types;
var iterateAndMeasure = require('./_measure');

iterateAndMeasure(function() { return new types.String('hi'); });
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"coverage": "node scripts/coverage.js",
"install": "node scripts/install.js",
"postinstall": "node scripts/build.js",
"lint": "node_modules/.bin/eslint bin/node-sass lib scripts test",
"lint": "node_modules/.bin/eslint bin/node-sass .",
"test": "node_modules/.bin/mocha test/{*,**/**}.js",
"build": "node scripts/build.js --force",
"prepublish": "not-in-install && node scripts/prepublish.js || in-install"
Expand Down
5 changes: 3 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ function parseArgs(args) {
if (arg === '-f' || arg === '--force') {
options.force = true;
return false;
} else if (arg.substring(0, 13) === '--target_arch') {
}
if (arg.substring(0, 13) === '--target_arch') {
options.arch = arg.substring(14);
} else if (arg === '-d' || arg === '--debug') {
options.debug = true;
Expand Down Expand Up @@ -135,7 +136,7 @@ function testBinary(options) {
console.log('Testing binary');

try {
require('../').renderSync({
require('..').renderSync({
data: 's { a: ss }'
});

Expand Down
4 changes: 2 additions & 2 deletions scripts/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function coverage() {
fs.readFile(path.join('coverage', 'lcov.info'), function(err, data) {
if (err) { console.error(err); }
coveralls.handleInput(data.toString(),
function (err) { if (err) { console.error(err); } });
function(err) { if (err) { console.error(err); } });
});
});
lcov.writeReport(collector, true);
Expand Down Expand Up @@ -64,7 +64,7 @@ function coverage() {
});
process.env.NODESASS_COV = 1;
mocha.reporter(rep).run(function(failures) {
process.on('exit', function () {
process.on('exit', function() {
process.exit(failures);
});
});
Expand Down
2 changes: 1 addition & 1 deletion scripts/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function checkAndDownloadBinary() {
mkdir.sync(path.dirname(cachedBinary));
fs.createReadStream(binaryPath)
.pipe(fs.createWriteStream(cachedBinary))
.on('error', function (err) {
.on('error', function(err) {
console.log('Failed to cache binary:', err);
});
} catch (err) {
Expand Down
Loading