Skip to content

Commit a067d50

Browse files
committed
npm run-script lint runs clean
Moved test files with ES6 syntax or that test corresponding files in lib/es6 into test/unit/es6. Added a minimal .eslintrc to the directories for conditionally included ES6 source files.
1 parent faf461c commit a067d50

File tree

10 files changed

+25
-20
lines changed

10 files changed

+25
-20
lines changed

lib/SqlString.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var CHARS_ESCAPE_MAP = {
1414
'\'' : '\\\'',
1515
'\\' : '\\\\'
1616
};
17-
var ONE_ID_PATTERN = '^`(?:[^`]|``)+`$' // TODO(mikesamuel): Should allow ``?
17+
var ONE_ID_PATTERN = '^`(?:[^`]|``)+`$'; // TODO(mikesamuel): Should allow ``?
1818
// One or more Identifiers separated by dots.
1919
var QUALIFIED_ID_REGEXP = new RegExp(
2020
'^' + ONE_ID_PATTERN + '(?:[.]' + ONE_ID_PATTERN + ')*$');

lib/Template.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
/* eslint no-unused-vars: "off" */
2+
13
try {
2-
module.exports = require('./es6/Template')
4+
module.exports = require('./es6/Template');
35
} catch (ignored) {
46
// ES6 code failed to load.
57
//
@@ -13,14 +15,14 @@ try {
1315
// calledAsTemplateTagQuick unless that function has
1416
// returned true.
1517

16-
module.exports = function (staticStrings) {
18+
module.exports = function (sqlStrings) {
1719
// This might be reached if client code is transpiled down to
1820
// ES5 but this module is not.
1921
throw new Error('ES6 features not supported');
2022
};
2123
/**
22-
* @param {*} firstArg
23-
* @param {number} nArgs
24+
* @param {*} firstArg The first argument to the function call.
25+
* @param {number} nArgs The number of arguments pass to the function call.
2426
*
2527
* @return {boolean} always false in ES<6 compatibility mode.
2628
*/

lib/es6/.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"parserOptions": { "ecmaVersion": 6 }
3+
}

lib/es6/Template.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ const SqlString = require('../SqlString');
44
const {
55
calledAsTemplateTagQuick,
66
memoizedTagFunction,
7-
trimCommonWhitespaceFromLines,
8-
TypedString
7+
trimCommonWhitespaceFromLines
98
} = require('template-tag-common');
109
const { makeLexer } = require('./Lexer');
1110

test/unit/es6/.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"parserOptions": { "ecmaVersion": 6 }
3+
}

test/unit/es6-Lexer.js renamed to test/unit/es6/Lexer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var assert = require('assert');
44
var test = require('utest');
5-
var Lexer = require('../../lib/es6/Lexer');
5+
var Lexer = require('../../../lib/es6/Lexer');
66

77
function tokens (...chunks) {
88
const lexer = Lexer.makeLexer();

test/unit/es6-Template.js renamed to test/unit/es6/Template.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This file uses es6 features and is loaded conditionally.
22

33
var assert = require('assert');
4-
var SqlString = require('../../');
4+
var SqlString = require('../../../');
55
var test = require('utest');
66

77
var sql = SqlString.sql;
@@ -44,7 +44,7 @@ test('template tag', {
4444
runTagTest(
4545
'SELECT "\x1f8p\xbe\\\'OlI\xb3\xe3\\Z\x0cg(\x95\x7f"',
4646
() =>
47-
sql`SELECT "${Buffer.from("1f3870be274f6c49b3e31a0c6728957f","hex")}"`
47+
sql`SELECT "${Buffer.from('1f3870be274f6c49b3e31a0c6728957f','hex')}"`
4848
);
4949
},
5050
'null': function () {
@@ -61,7 +61,7 @@ test('template tag', {
6161
sql`SELECT ${undefined}`
6262
);
6363
},
64-
'undefined': function () {
64+
'negative zero': function () {
6565
runTagTest(
6666
'SELECT (1 / 0)',
6767
() =>

test/unit/test-Lexer.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
var assert = require('assert');
21
var process = require('process');
3-
var test = require('utest');
42

53
// If we're on a Node runtime that should support ES6, run the ES6 tests.
64
var nodeVersion = process.env.npm_config_node_version;
75
if (/^[0-5][.]/.test(nodeVersion || '')) {
86
// The major version is a single digit in [0, 5].
97
console.info('Skipping ES6 tests for node_version %s', nodeVersion);
108
} else {
11-
require('./es6-Lexer')
9+
require('./es6/Lexer');
1210
}

test/unit/test-SqlString.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,15 @@ test('SqlString.identifier', {
362362

363363
'toSqlString returns escaped id': function() {
364364
assert.equal(
365-
SqlString.identifier("Hello, World!").toSqlString(),
366-
"`Hello, World!`");
365+
SqlString.identifier('Hello, World!').toSqlString(),
366+
'`Hello, World!`');
367367
},
368368

369369
'backticks escaped': function() {
370-
assert.equal(SqlString.identifier("I`m").toSqlString(), "`I``m`");
370+
assert.equal(SqlString.identifier('I`m').toSqlString(), '`I``m`');
371371
},
372372

373373
'escape() does not re-escape': function() {
374-
assert.equal(SqlString.escape(SqlString.identifier("I`m")), "`I``m`");
374+
assert.equal(SqlString.escape(SqlString.identifier('I`m')), '`I``m`');
375375
}
376376
});

test/unit/test-Template.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if (/^[0-5][.]/.test(nodeVersion || '')) {
99
// The major version is a single digit in [0, 5].
1010
console.info('Skipping ES6 tests for node_version %s', nodeVersion);
1111
} else {
12-
require('./es6-Template')
12+
require('./es6/Template');
1313
}
1414

1515
var sql = SqlString.sql;
@@ -26,4 +26,4 @@ test('sql.calledAsTemplateTagQuick', {
2626
'string array first': function () {
2727
assert.equal(sql.calledAsTemplateTagQuick([''], 2), false);
2828
}
29-
})
29+
});

0 commit comments

Comments
 (0)