From 48b4cdc93e8f5e120011c20ef7cc96b32516b658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Mon, 30 Mar 2020 19:08:20 +0100 Subject: [PATCH] Upgrade to Standard v14 --- examples/clientsideserver.js | 14 ++--- lib/core/alignment-pattern.js | 2 +- lib/core/qrcode.js | 6 +- lib/core/segments.js | 4 +- package.json | 2 +- test/e2e/toDataURL.test.js | 2 +- test/e2e/toFile.test.js | 4 +- test/unit/core/mode.test.js | 1 + test/unit/core/segments.test.js | 107 ++++++++++++++++---------------- test/unit/renderer/svg.test.js | 42 ++++++++----- 10 files changed, 98 insertions(+), 86 deletions(-) diff --git a/examples/clientsideserver.js b/examples/clientsideserver.js index 03f79a21..be12e49b 100644 --- a/examples/clientsideserver.js +++ b/examples/clientsideserver.js @@ -9,10 +9,10 @@ var Image = Canvas.Image var path = require('path') - // app.use(express.methodOverride()) - // app.use(express.bodyParser()) -// app.use(app.router) - // app.use(express.static(path.resolve(__dirname, '..'))) +// app.use(express.methodOverride()) +// app.use(express.bodyParser()) +// app.use(app.router) +// app.use(express.static(path.resolve(__dirname, '..'))) app.get('/qrcode.js', (req, res) => { res.set('content-type', 'text/javascript') @@ -162,7 +162,7 @@ effectHandlers.rounded = function (args, cb) { } } }) - cb(false, canvas) + cb(null, canvas) }) } @@ -210,7 +210,7 @@ effectHandlers.remoteImage = function (args, cb) { }) res.on('complete', function () { - cb(false, data) + cb(null, data) }) res.on('error', function (error) { @@ -292,7 +292,7 @@ effectHandlers.image = function (args, cb) { cb(err, false) } - cb(false, baconCanvas) + cb(null, baconCanvas) }) } diff --git a/lib/core/alignment-pattern.js b/lib/core/alignment-pattern.js index 36f1142e..61c82312 100644 --- a/lib/core/alignment-pattern.js +++ b/lib/core/alignment-pattern.js @@ -69,7 +69,7 @@ exports.getPositions = function getPositions (version) { for (var i = 0; i < posLength; i++) { for (var j = 0; j < posLength; j++) { // Skip if position is occupied by finder patterns - if ((i === 0 && j === 0) || // top-left + if ((i === 0 && j === 0) || // top-left (i === 0 && j === posLength - 1) || // bottom-left (i === posLength - 1 && j === 0)) { // top-right continue diff --git a/lib/core/qrcode.js b/lib/core/qrcode.js index d97ebfeb..c1c4c9e1 100644 --- a/lib/core/qrcode.js +++ b/lib/core/qrcode.js @@ -388,8 +388,7 @@ function createSymbol (data, version, errorCorrectionLevel, maskPattern) { var rawSegments = Segments.rawSplit(data) // Estimate best version that can contain raw splitted segments - estimatedVersion = Version.getBestVersionForData(rawSegments, - errorCorrectionLevel) + estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel) } // Build optimized segments @@ -400,8 +399,7 @@ function createSymbol (data, version, errorCorrectionLevel, maskPattern) { } // Get the min version that can contain data - var bestVersion = Version.getBestVersionForData(segments, - errorCorrectionLevel) + var bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel) // If no version is found, data cannot be stored if (!bestVersion) { diff --git a/lib/core/segments.js b/lib/core/segments.js index 15ceb664..c9d8c4ea 100644 --- a/lib/core/segments.js +++ b/lib/core/segments.js @@ -179,7 +179,7 @@ function buildNodes (segs) { */ function buildGraph (nodes, version) { var table = {} - var graph = {'start': {}} + var graph = { start: {} } var prevNodeIds = ['start'] for (var i = 0; i < nodes.length; i++) { @@ -216,7 +216,7 @@ function buildGraph (nodes, version) { } for (n = 0; n < prevNodeIds.length; n++) { - graph[prevNodeIds[n]]['end'] = 0 + graph[prevNodeIds[n]].end = 0 } return { map: graph, table: table } diff --git a/package.json b/package.json index 63e1e780..7830074c 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "htmlparser2": "^3.9.2", "os-tmpdir": "^1.0.2", "sinon": "^1.17.7", - "standard": "^9.0.2", + "standard": "^14.3.3", "tap": "^12.1.1", "uglify-js": "^2.7.5" }, diff --git a/test/e2e/toDataURL.test.js b/test/e2e/toDataURL.test.js index 18e2ad19..15d2660f 100644 --- a/test/e2e/toDataURL.test.js +++ b/test/e2e/toDataURL.test.js @@ -124,7 +124,7 @@ test('Canvas toDataURL - image/png', function (t) { 'Should throw if no arguments are provided') t.throw(function () { QRCodeBrowser.toDataURL(function () {}) }, - 'Should throw if text is not provided') + 'Should throw if text is not provided') var canvas = new Canvas(200, 200) QRCodeBrowser.toDataURL(canvas, 'i am a pony!', { diff --git a/test/e2e/toFile.test.js b/test/e2e/toFile.test.js index ccc59b55..d25b94d9 100644 --- a/test/e2e/toFile.test.js +++ b/test/e2e/toFile.test.js @@ -121,9 +121,7 @@ test('toFile png', function (t) { test('toFile svg', function (t) { var fileName = path.join(tmpDir(), 'qrimage.svg') var expectedOutput = fs.readFileSync( - path.join(__dirname, - '/svg.expected.out'), - 'UTF-8') + path.join(__dirname, '/svg.expected.out'), 'UTF-8') t.plan(6) diff --git a/test/unit/core/mode.test.js b/test/unit/core/mode.test.js index 8418a7c6..42d4fd5d 100644 --- a/test/unit/core/mode.test.js +++ b/test/unit/core/mode.test.js @@ -59,6 +59,7 @@ test('Char count bits', function (t) { }) test('Best mode', function (t) { + /* eslint-disable quote-props */ var EXPECTED_MODE = { '12345': Mode.NUMERIC, 'abcde': Mode.BYTE, diff --git a/test/unit/core/segments.test.js b/test/unit/core/segments.test.js index dfc209d1..2cff280b 100644 --- a/test/unit/core/segments.test.js +++ b/test/unit/core/segments.test.js @@ -10,127 +10,127 @@ var Utils = require('core/utils') var testData = [ { input: '1A1', - result: [{data: '1A1', mode: Mode.ALPHANUMERIC}] + result: [{ data: '1A1', mode: Mode.ALPHANUMERIC }] }, { input: 'a-1-b-2?', - result: [{data: 'a-1-b-2?', mode: Mode.BYTE}] + result: [{ data: 'a-1-b-2?', mode: Mode.BYTE }] }, { input: 'AB123456CDF', - result: [{data: 'AB123456CDF', mode: Mode.ALPHANUMERIC}] + result: [{ data: 'AB123456CDF', mode: Mode.ALPHANUMERIC }] }, { input: 'aABC000000-?-----a', result: [ - {data: 'aABC', mode: Mode.BYTE}, - {data: '000000', mode: Mode.NUMERIC}, - {data: '-?-----a', mode: Mode.BYTE} + { data: 'aABC', mode: Mode.BYTE }, + { data: '000000', mode: Mode.NUMERIC }, + { data: '-?-----a', mode: Mode.BYTE } ] }, { input: 'aABC000000A?', result: [ - {data: 'aABC', mode: Mode.BYTE}, - {data: '000000', mode: Mode.NUMERIC}, - {data: 'A?', mode: Mode.BYTE} + { data: 'aABC', mode: Mode.BYTE }, + { data: '000000', mode: Mode.NUMERIC }, + { data: 'A?', mode: Mode.BYTE } ] }, { input: 'a1234ABCDEF?', result: [ - {data: 'a', mode: Mode.BYTE}, - {data: '1234ABCDEF', mode: Mode.ALPHANUMERIC}, - {data: '?', mode: Mode.BYTE} + { data: 'a', mode: Mode.BYTE }, + { data: '1234ABCDEF', mode: Mode.ALPHANUMERIC }, + { data: '?', mode: Mode.BYTE } ] }, { input: '12345A12345', result: [ - {data: '12345A12345', mode: Mode.ALPHANUMERIC} + { data: '12345A12345', mode: Mode.ALPHANUMERIC } ] }, { input: 'aABCDEFGHILMNa', result: [ - {data: 'a', mode: Mode.BYTE}, - {data: 'ABCDEFGHILMN', mode: Mode.ALPHANUMERIC}, - {data: 'a', mode: Mode.BYTE} + { data: 'a', mode: Mode.BYTE }, + { data: 'ABCDEFGHILMN', mode: Mode.ALPHANUMERIC }, + { data: 'a', mode: Mode.BYTE } ] }, { input: 'Aa12345', result: [ - {data: 'Aa', mode: Mode.BYTE}, - {data: '12345', mode: Mode.NUMERIC} + { data: 'Aa', mode: Mode.BYTE }, + { data: '12345', mode: Mode.NUMERIC } ] }, { input: 'a1A2B3C4D5E6F4G7', result: [ - {data: 'a', mode: Mode.BYTE}, - {data: '1A2B3C4D5E6F4G7', mode: Mode.ALPHANUMERIC} + { data: 'a', mode: Mode.BYTE }, + { data: '1A2B3C4D5E6F4G7', mode: Mode.ALPHANUMERIC } ] }, { input: '123456789QWERTYUIOPASD', result: [ - {data: '123456789', mode: Mode.NUMERIC}, - {data: 'QWERTYUIOPASD', mode: Mode.ALPHANUMERIC} + { data: '123456789', mode: Mode.NUMERIC }, + { data: 'QWERTYUIOPASD', mode: Mode.ALPHANUMERIC } ] }, { input: 'QWERTYUIOPASD123456789', result: [ - {data: 'QWERTYUIOPASD', mode: Mode.ALPHANUMERIC}, - {data: '123456789', mode: Mode.NUMERIC} + { data: 'QWERTYUIOPASD', mode: Mode.ALPHANUMERIC }, + { data: '123456789', mode: Mode.NUMERIC } ] }, { input: 'ABCDEF123456a', result: [ - {data: 'ABCDEF123456', mode: Mode.ALPHANUMERIC}, - {data: 'a', mode: Mode.BYTE} + { data: 'ABCDEF123456', mode: Mode.ALPHANUMERIC }, + { data: 'a', mode: Mode.BYTE } ] }, { input: 'abcdefABCDEF', result: [ - {data: 'abcdef', mode: Mode.BYTE}, - {data: 'ABCDEF', mode: Mode.ALPHANUMERIC} + { data: 'abcdef', mode: Mode.BYTE }, + { data: 'ABCDEF', mode: Mode.ALPHANUMERIC } ] }, { input: 'a123456ABCDEa', result: [ - {data: 'a', mode: Mode.BYTE}, - {data: '123456ABCDE', mode: Mode.ALPHANUMERIC}, - {data: 'a', mode: Mode.BYTE} + { data: 'a', mode: Mode.BYTE }, + { data: '123456ABCDE', mode: Mode.ALPHANUMERIC }, + { data: 'a', mode: Mode.BYTE } ] }, { input: 'AAAAA12345678?A1A', result: [ - {data: 'AAAAA', mode: Mode.ALPHANUMERIC}, - {data: '12345678', mode: Mode.NUMERIC}, - {data: '?A1A', mode: Mode.BYTE} + { data: 'AAAAA', mode: Mode.ALPHANUMERIC }, + { data: '12345678', mode: Mode.NUMERIC }, + { data: '?A1A', mode: Mode.BYTE } ] }, { input: 'Aaa', - result: [{data: 'Aaa', mode: Mode.BYTE}] + result: [{ data: 'Aaa', mode: Mode.BYTE }] }, { input: 'Aa12345A', result: [ - {data: 'Aa', mode: Mode.BYTE}, - {data: '12345A', mode: Mode.ALPHANUMERIC} + { data: 'Aa', mode: Mode.BYTE }, + { data: '12345A', mode: Mode.ALPHANUMERIC } ] }, { input: 'ABC\nDEF', result: [ - {data: 'ABC\nDEF', mode: Mode.BYTE} + { data: 'ABC\nDEF', mode: Mode.BYTE } ] } ] @@ -138,24 +138,24 @@ var testData = [ var kanjiTestData = [ { input: '乂ЁЖぞβ', - result: [{data: '乂ЁЖぞβ', mode: Mode.KANJI}] + result: [{ data: '乂ЁЖぞβ', mode: Mode.KANJI }] }, { input: 'ΑΒΓψωЮЯабв', - result: [{data: 'ΑΒΓψωЮЯабв', mode: Mode.KANJI}] + result: [{ data: 'ΑΒΓψωЮЯабв', mode: Mode.KANJI }] }, { input: '皿a晒三', result: [ - {data: '皿a', mode: Mode.BYTE}, - {data: '晒三', mode: Mode.KANJI} + { data: '皿a', mode: Mode.BYTE }, + { data: '晒三', mode: Mode.KANJI } ] }, { input: '皿a\n晒三', result: [ - {data: '皿a\n', mode: Mode.BYTE}, - {data: '晒三', mode: Mode.KANJI} + { data: '皿a\n', mode: Mode.BYTE }, + { data: '晒三', mode: Mode.KANJI } ] } ] @@ -163,22 +163,23 @@ var kanjiTestData = [ testData = testData.concat(kanjiTestData) test('Segments from array', function (t) { - t.deepEqual(Segments.fromArray(['abcdef', '12345']), + t.deepEqual( + Segments.fromArray(['abcdef', '12345']), [new ByteData('abcdef'), new NumericData('12345')], 'Should return correct segment from array of string') - t.deepEqual(Segments.fromArray( - [{ data: 'abcdef', mode: Mode.BYTE }, { data: '12345', mode: Mode.NUMERIC }]), + t.deepEqual( + Segments.fromArray([{ data: 'abcdef', mode: Mode.BYTE }, { data: '12345', mode: Mode.NUMERIC }]), [new ByteData('abcdef'), new NumericData('12345')], 'Should return correct segment from array of objects') - t.deepEqual(Segments.fromArray( - [{ data: 'abcdef', mode: 'byte' }, { data: '12345', mode: 'numeric' }]), + t.deepEqual( + Segments.fromArray([{ data: 'abcdef', mode: 'byte' }, { data: '12345', mode: 'numeric' }]), [new ByteData('abcdef'), new NumericData('12345')], 'Should return correct segment from array of objects if mode is specified as string') - t.deepEqual(Segments.fromArray( - [{ data: 'abcdef' }, { data: '12345' }]), + t.deepEqual( + Segments.fromArray([{ data: 'abcdef' }, { data: '12345' }]), [new ByteData('abcdef'), new NumericData('12345')], 'Should return correct segment from array of objects if mode is not specified') @@ -188,8 +189,8 @@ test('Segments from array', function (t) { t.throw(function () { Segments.fromArray([{ data: 'ABCDE', mode: 'numeric' }]) }, 'Should throw if segment cannot be encoded with specified mode') - t.deepEqual(Segments.fromArray( - [{ data: '0123', mode: Mode.KANJI }]), [new ByteData('0123')], + t.deepEqual( + Segments.fromArray([{ data: '0123', mode: Mode.KANJI }]), [new ByteData('0123')], 'Should use Byte mode if kanji support is disabled') t.end() diff --git a/test/unit/renderer/svg.test.js b/test/unit/renderer/svg.test.js index 1b41a8cd..5b8aae82 100644 --- a/test/unit/renderer/svg.test.js +++ b/test/unit/renderer/svg.test.js @@ -67,19 +67,25 @@ test('Svg render', function (t) { light: '#ffffff80' } }, [ - { name: 'svg', + { + name: 'svg', attribs: [ { name: 'viewbox', value: getExpectedViewbox(size, 4) } - ]}, - { name: 'path', + ] + }, + { + name: 'path', attribs: [ { name: 'fill', value: '#ffffff' }, { name: 'fill-opacity', value: '.50' } - ]}, - { name: 'path', + ] + }, + { + name: 'path', attribs: [ { name: 'stroke', value: '#000000' } - ]} + ] + } ])) tests.push(buildTest(t, data, { @@ -90,33 +96,41 @@ test('Svg render', function (t) { dark: '#00000080' } }, [ - { name: 'svg', + { + name: 'svg', attribs: [ { name: 'viewbox', value: getExpectedViewbox(size, 8) } - ]}, - { name: 'path', + ] + }, + { + name: 'path', attribs: [ { name: 'stroke', value: '#000000' }, { name: 'stroke-opacity', value: '.50' } - ]} + ] + } ])) tests.push(buildTest(t, data, {}, [ - { name: 'svg', + { + name: 'svg', attribs: [ { name: 'viewbox', value: getExpectedViewbox(size, 4) } - ]}, + ] + }, { name: 'path', attribs: [{ name: 'fill', value: '#ffffff' }] }, { name: 'path', attribs: [{ name: 'stroke', value: '#000000' }] } ])) tests.push(buildTest(t, data, { width: 250 }, [ - { name: 'svg', + { + name: 'svg', attribs: [ { name: 'width', value: '250' }, { name: 'height', value: '250' }, { name: 'viewbox', value: getExpectedViewbox(size, 4) } - ]}, + ] + }, { name: 'path', attribs: [{ name: 'fill', value: '#ffffff' }] }, { name: 'path', attribs: [{ name: 'stroke', value: '#000000' }] } ]))