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

Commit

Permalink
Use ES2015 template strings instead of string concatenation.
Browse files Browse the repository at this point in the history
  • Loading branch information
realityking committed Apr 6, 2018
1 parent 606eab0 commit 3362b12
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 41 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
},
"globals": {},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2015
},
"rules": {
"no-bitwise": 2,
"camelcase": 0,
Expand Down Expand Up @@ -41,6 +44,8 @@
"no-extra-semi": 2,
"no-redeclare": 2,
"block-scoped-var": 2,
"no-console": 0
"no-console": 0,
"no-useless-concat": 2,
"prefer-template": 2
}
}
4 changes: 2 additions & 2 deletions bin/node-sass
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ function getOptions(args, options) {
var sourceMapIsDirectory = options.sourceMapOriginal.indexOf('.map', options.sourceMapOriginal.length - 4) === -1 && isDirectory(options.sourceMapOriginal);

if (options.sourceMapOriginal === 'true') {
options.sourceMap = options.dest + '.map';
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');
options.sourceMap = path.resolve(options.sourceMapOriginal, `${path.basename(options.dest)}.map`);
} else {
sassDir = path.resolve(options.directory);
file = path.relative(sassDir, args[0]);
Expand Down
10 changes: 5 additions & 5 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function foundBinaries() {

function foundBinariesList() {
return sass.getInstalledBinaries().map(function(env) {
return ' - ' + sass.getHumanEnvironment(env);
return ` - ${sass.getHumanEnvironment(env)}`;
}).join('\n');
}

Expand All @@ -31,16 +31,16 @@ function missingBinaryFooter() {

module.exports.unsupportedEnvironment = function() {
return [
'Node Sass does not yet support your current environment: ' + humanEnvironment(),
`Node Sass does not yet support your current environment: ${humanEnvironment()}`,
'For more information on which environments are supported please see:',
'https://github.com/sass/node-sass/releases/tag/v' + pkg.version
`https://github.com/sass/node-sass/releases/tag/v${pkg.version}`
].join('\n');
};

module.exports.missingBinary = function() {
return [
'Missing binding ' + sass.getBinaryPath(),
'Node Sass could not find a binding for your current environment: ' + humanEnvironment(),
`Missing binding ${ sass.getBinaryPath()}`,
`Node Sass could not find a binding for your current environment: ${humanEnvironment()}`,
'',
foundBinaries(),
'',
Expand Down
12 changes: 6 additions & 6 deletions lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ function getHumanEnvironment(env) {
runtime = getHumanNodeVersion(parts[2]);

if (parts.length !== 3) {
return 'Unknown environment (' + binding + ')';
return `Unknown environment (${binding})`;
}

if (!platform) {
platform = 'Unsupported platform (' + parts[0] + ')';
platform = `Unsupported platform (${parts[0]})`;
}

if (!arch) {
arch = 'Unsupported architecture (' + parts[1] + ')';
arch = `Unsupported architecture (${parts[1]})`;
}

if (!runtime) {
runtime = 'Unsupported runtime (' + parts[2] + ')';
runtime = `Unsupported runtime (${parts[2]})`;
}

return [
Expand Down Expand Up @@ -194,7 +194,7 @@ function getBinaryName() {
} else {
variant = getPlatformVariant();
if (variant) {
platform += '_' + variant;
platform += `_${variant}`;
}

binaryName = [
Expand Down Expand Up @@ -242,7 +242,7 @@ function getBinaryUrl() {
(pkg.nodeSassConfig && pkg.nodeSassConfig.binarySite) ||
'https://github.com/sass/node-sass/releases/download';

return [site, 'v' + pkg.version, getBinaryName()].join('/');
return [site, `v${pkg.version}`, getBinaryName()].join('/');
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function getSourceMap(options) {
var sourceMap = options.sourceMap;

if (sourceMap && typeof sourceMap !== 'string' && options.outFile) {
sourceMap = options.outFile + '.map';
sourceMap = `${options.outFile}.map`;
}

return sourceMap && typeof sourceMap === 'string' ? path.resolve(sourceMap) : null;
Expand Down Expand Up @@ -250,11 +250,11 @@ function tryCallback(callback, args) {
function normalizeFunctionSignature(signature, callback) {
if (!/^\*|@warn|@error|@debug|\w+\(.*\)$/.test(signature)) {
if (!/\w+/.test(signature)) {
throw new Error('Invalid function signature format "' + signature + '"');
throw new Error(`Invalid function signature format "${signature}"`);
}

return {
signature: signature + '(...)',
signature: `${signature}(...)`,
callback: function() {
var args = Array.prototype.slice.call(arguments),
list = args.shift(),
Expand Down
6 changes: 3 additions & 3 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = function(options, emitter) {
return emitter.emit('error', chalk.red(err));
}

emitter.emit('warn', chalk.green('Wrote CSS to ' + destination));
emitter.emit('warn', chalk.green(`Wrote CSS to ${ destination}`));
emitter.emit('write', err, destination, result.css.toString());
done();
});
Expand All @@ -91,10 +91,10 @@ module.exports = function(options, emitter) {
}
fs.writeFile(sourceMap, result.map, function(err) {
if (err) {
return emitter.emit('error', chalk.red('Error' + err));
return emitter.emit('error', chalk.red(`Error${err}`));
}

emitter.emit('warn', chalk.green('Wrote Source Map to ' + sourceMap));
emitter.emit('warn', chalk.green(`Wrote Source Map to ${sourceMap}`));
emitter.emit('write-source-map', err, sourceMap, result.map);
done();
});
Expand Down
8 changes: 4 additions & 4 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ describe('api', function() {
return sass.NULL;
}
done({
file: fixture('include-files/' + url + '.scss')
file: fixture(`include-files/${url}.scss`)
});
}
}, function(err, data) {
Expand Down Expand Up @@ -734,7 +734,7 @@ describe('api', function() {
functions: {
'foo($a)': function(str) {
str = str.getValue().replace(/['"]/g, '');
return new sass.types.String('"' + str + str + '"');
return new sass.types.String(`"${str}${str}"`);
}
}
}, function(error, result) {
Expand All @@ -749,7 +749,7 @@ describe('api', function() {
functions: {
'foo($a)': function(str) {
var unquoted = str.getValue().replace(/['"]/g, '');
str.setValue('"' + unquoted + unquoted + '"');
str.setValue(`"${unquoted}${unquoted}"`);
return str;
}
}
Expand Down Expand Up @@ -1771,7 +1771,7 @@ describe('api', function() {
list = new sass.types.List(t - f + 1);

for (i = f; i <= t; i++) {
list.setValue(i - f, new sass.types.String('h' + i));
list.setValue(i - f, new sass.types.String(`h${i}`));
}

return list;
Expand Down
2 changes: 1 addition & 1 deletion test/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('binding', function() {
assert.throws(
function() { binding(etx); },
function(err) {
var re = new RegExp('Missing binding.*?\\' + path.sep + 'vendor\\' + path.sep);
var re = new RegExp(`Missing binding.*?\\${path.sep}vendor\\${path.sep}`);
if ((err instanceof Error)) {
return re.test(err);
}
Expand Down
2 changes: 1 addition & 1 deletion test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ describe('cli', function() {

bin.stderr.setEncoding('utf8');
bin.stderr.once('data', function(data) {
assert.strictEqual(data.trim(), '=> changed: ' + src);
assert.strictEqual(data.trim(), `=> changed: ${src}`);
fs.unlinkSync(src);
bin.kill();
done();
Expand Down
4 changes: 2 additions & 2 deletions test/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('binary errors', function() {
}

function getCurrentEnvironment() {
return getCurrentPlatform() + ' ' + getCurrentArchitecture();
return `${getCurrentPlatform()} ${getCurrentArchitecture()}`;
}

describe('for an unsupported environment', function() {
Expand All @@ -46,7 +46,7 @@ describe('binary errors', function() {

it('documents the expected binary location', function() {
var message = errors.missingBinary();
assert.ok(message.indexOf(path.sep + 'vendor' + path.sep) !== -1);
assert.ok(message.indexOf(`${path.sep}vendor${path.sep}`) !== -1);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ var sass = require('../../..');
module.exports = {
'foo($a)': function(str) {
str = str.getValue().replace(/['"]/g, '');
return new sass.types.String('"' + str + str + '"');
return new sass.types.String(`"${str}${str}"`);
}
};
12 changes: 6 additions & 6 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var normalize = function(str) {
return str.replace(/\s+/g, '');
};

var inputs = glob.sync(specPath + '/**/input.*');
var inputs = glob.sync(`${specPath}/**/input.*`);

var initialize = function(inputCss, options) {
var testCase = {};
Expand Down Expand Up @@ -61,7 +61,7 @@ var runTest = function(inputCssPath, options) {
if (test.todo || test.warningTodo) {
this.skip('Test marked with TODO');
} else if (test.only && test.only.indexOf(impl) === -1) {
this.skip('Tests marked for only: ' + test.only.join(', '));
this.skip(`Tests marked for only: ${test.only.join(', ')}`);
} else if (version < test.startVersion) {
this.skip('Tests marked for newer Sass versions only');
} else if (version > test.endVersion) {
Expand Down Expand Up @@ -90,13 +90,13 @@ var runTest = function(inputCssPath, options) {
assert.equal(
error.formatted.toString().split('\n')[0],
expectedError.toString().split('\n')[0],
'Should Error.\nOptions' + JSON.stringify(test.options));
`Should Error.\nOptions${JSON.stringify(test.options)}`);
}
} else if (expected) {
assert.equal(
normalize(result.css.toString()),
expected,
'Should equal with options ' + JSON.stringify(test.options)
`Should equal with options ${JSON.stringify(test.options)}`
);
}
done();
Expand Down Expand Up @@ -150,7 +150,7 @@ var executeSuite = function(suite, tests) {
executeSuite(
{
name: prevSuite,
folder: suite.folder + '/' + prevSuite,
folder: `${suite.folder}/${prevSuite}`,
tests: [],
suites: [],
options: Object.assign({}, suite.options),
Expand All @@ -166,7 +166,7 @@ var executeSuite = function(suite, tests) {
executeSuite(
{
name: suiteName,
folder: suite.folder + '/' + suiteName,
folder: `${suite.folder}/${suiteName}`,
tests: [],
suites: [],
options: Object.assign({}, suite.options),
Expand Down
6 changes: 3 additions & 3 deletions test/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ describe('sass.types', function() {
assert.equal(error.message, 'Supplied value should be a number');

return true;
}, 'argument was: ' + arg);
}, `argument was: ${arg}`);
}

assertJustOneArgument(function() { c.setR(); });
Expand Down Expand Up @@ -328,7 +328,7 @@ describe('sass.types', function() {
assert.ok(error instanceof TypeError);
assert.equal(error.message, 'Supplied value should be a boolean');
return true;
}, 'setSeparator(' + arg + ')');
}, `setSeparator(${arg})`);
});
});

Expand All @@ -352,7 +352,7 @@ describe('sass.types', function() {
assert.equal(error.message, 'Supplied index should be an integer');

return true;
}, 'getValue(' + arg + ')');
}, `getValue(${arg})`);
});

assert.throws(function() {
Expand Down
6 changes: 3 additions & 3 deletions test/useragent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ var assert = require('assert'),
describe('util', function() {
describe('useragent', function() {
it('should look as we expect', function() {
var reNode = 'node/' + process.version;
var reSass = 'node-sass-installer/' + pkg.version;
var reUA = new RegExp('^' + reNode + ' ' + reSass + '$');
var reNode = `node/${process.version}`;
var reSass = `node-sass-installer/${pkg.version}`;
var reUA = new RegExp(`^${reNode} ${reSass}$`);

assert.ok(reUA.test(ua()));
});
Expand Down

0 comments on commit 3362b12

Please sign in to comment.