From 2ad8d4eee028385b2b9aa72849441f7c7905ca14 Mon Sep 17 00:00:00 2001 From: abetomo Date: Wed, 16 Dec 2020 14:18:01 +0900 Subject: [PATCH 1/2] Upgrade standard to 16 * fix tests * run `standard --fix` --- cli.js | 24 ++++++++++++------------ index.js | 4 ++-- lib/codeBlockUtils.js | 16 ++++++++-------- lib/formatter.js | 4 ++-- lib/linter.js | 2 +- package.json | 6 ++++-- tests/index.js | 23 +++++++++++++---------- 7 files changed, 42 insertions(+), 37 deletions(-) diff --git a/cli.js b/cli.js index e4cda0c..4cc8903 100755 --- a/cli.js +++ b/cli.js @@ -1,13 +1,13 @@ #!/usr/bin/env node 'use strict' -var fs = require('fs') -var globby = require('globby') -var path = require('path') -var program = require('commander') -var standardMarkdown = require('./') +const fs = require('fs') +const globby = require('globby') +const path = require('path') +const program = require('commander') +const standardMarkdown = require('./') -var patterns = [ +let patterns = [ '**/*.md', '**/*.markdown', '!**/.git/**', @@ -19,7 +19,7 @@ var patterns = [ '!bundle.js' ] -var cwd +let cwd program .version(require('./package.json').version) @@ -43,11 +43,11 @@ program cwd = cwd || process.cwd() // The files to run our command against -var files = globby.sync(patterns, { cwd: cwd }).map(function (file) { +const files = globby.sync(patterns, { cwd: cwd }).map(function (file) { return path.resolve(cwd, file) }) -var afterLint = function () {} +let afterLint = function () {} // Auto fix the files first if we were told to if (program.fix) { @@ -68,8 +68,8 @@ standardMarkdown[program.fix ? 'formatFiles' : 'lintFiles'](files, function (err process.exit(0) } - var lastFilePath - var totalErrors = 0 + let lastFilePath + let totalErrors = 0 function pad (width, string, padding) { return (width <= string.length) ? string : pad(width, string + padding, padding) } @@ -80,7 +80,7 @@ standardMarkdown[program.fix ? 'formatFiles' : 'lintFiles'](files, function (err results.forEach(function (result) { totalErrors += result.errors.length result.errors.forEach(function (error) { - var filepath = path.relative(cwd, result.file) + const filepath = path.relative(cwd, result.file) if (filepath !== lastFilePath) { console.log('\n ' + filepath) } diff --git a/index.js b/index.js index f62ceba..3f97448 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ 'use strict' -var formatter = require('./lib/formatter') -var linter = require('./lib/linter') +const formatter = require('./lib/formatter') +const linter = require('./lib/linter') module.exports = { formatFiles: formatter.formatFiles, diff --git a/lib/codeBlockUtils.js b/lib/codeBlockUtils.js index 70a65b1..3d5e52c 100644 --- a/lib/codeBlockUtils.js +++ b/lib/codeBlockUtils.js @@ -1,18 +1,18 @@ 'use strict' -var blockOpener = /^```(js|javascript)$/mg -var blockCloser = /^```$/mg +const blockOpener = /^```(js|javascript)$/mg +const blockCloser = /^```$/mg // Extract all code blocks in the file function extractCodeBlocks (text) { - var currentBlock = '' - var blocks = [] - var insideBlock = false - var lines = text.split('\n') - var startLine + let currentBlock = '' + const blocks = [] + let insideBlock = false + const lines = text.split('\n') + let startLine lines.forEach(function (line, index) { - var originalLine = line + const originalLine = line // standard doesn't like trailing whitespace line = line.replace(/\s*$/, '') diff --git a/lib/formatter.js b/lib/formatter.js index 2ac08ad..538767a 100644 --- a/lib/formatter.js +++ b/lib/formatter.js @@ -1,8 +1,8 @@ 'use strict' -var linter = require('./linter') +const linter = require('./linter') -var formatter = module.exports = {} +const formatter = module.exports = {} formatter.formatFiles = function (files, standardOptions, done) { if (typeof standardOptions === 'function') { diff --git a/lib/linter.js b/lib/linter.js index 91dccb9..49d3c9f 100644 --- a/lib/linter.js +++ b/lib/linter.js @@ -11,7 +11,7 @@ const disabledRules = [ 'no-undef', 'no-unused-expressions', 'no-unused-vars', - 'standard/no-callback-literal' + 'node/no-callback-literal' ] const eslintDisable = '/* eslint-disable ' + disabledRules.join(', ') + ' */\n' const linter = module.exports = {} diff --git a/package.json b/package.json index 45d3154..d9de1ef 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,9 @@ "version": "6.0.0", "description": "Test your Markdown files for Standard JavaScript Style™", "main": "index.js", - "bin": "cli.js", + "bin": { + "standard-markdown": "cli.js" + }, "scripts": { "test": "node tests/index.js | tap-spec && standard" }, @@ -25,7 +27,7 @@ "lodash.flatten": "^4.4.0", "lodash.range": "^3.2.0", "ora": "^4.0.3", - "standard": "^14.3.1" + "standard": "^16.0.3" }, "devDependencies": { "tap-spec": "^5.0.0", diff --git a/tests/index.js b/tests/index.js index 6ca19c0..646666a 100644 --- a/tests/index.js +++ b/tests/index.js @@ -1,12 +1,12 @@ 'use strict' -var test = require('tape') -var fs = require('fs') -var path = require('path') -var standardMarkdown = require('../') -var dirty = fs.readFileSync(path.join(__dirname, 'fixtures/dirty.md'), 'utf8') -var clean = fs.readFileSync(path.join(__dirname, 'fixtures/clean.md'), 'utf8') -var cleanable = fs.readFileSync(path.join(__dirname, 'fixtures/cleanable.md'), 'utf8') +const test = require('tape') +const fs = require('fs') +const path = require('path') +const standardMarkdown = require('../') +const dirty = fs.readFileSync(path.join(__dirname, 'fixtures/dirty.md'), 'utf8') +const clean = fs.readFileSync(path.join(__dirname, 'fixtures/clean.md'), 'utf8') +const cleanable = fs.readFileSync(path.join(__dirname, 'fixtures/cleanable.md'), 'utf8') test('standardMarkdownFormat', function (t) { t.comment('cleaning the dirty fixture') @@ -27,13 +27,16 @@ test('standardMarkdown', function (t) { if (err) throw err t.comment('dirty fixture') - t.equal(results.length, 5, 'returns six linting errors') + t.equal(results.length, 7, 'returns 7 linting errors') - t.equal(results[0].message, 'Extra semicolon.', 'finds errors in first block') + t.equal(results[0].message, 'Unexpected var, use let or const instead.') t.equal(results[0].line, 6, 'identifies correct line number in first block') t.equal(results[1].message, 'Extra semicolon.', 'finds errors in second block') - t.equal(results[1].line, 20, 'identifies correct line number in second block') + t.equal(results[1].line, 6, 'identifies correct line number in second block') + + t.equal(results[3].message, 'Extra semicolon.', 'finds errors in second block') + t.equal(results[3].line, 20, 'identifies correct line number in second block') t.comment('every error') t.ok(results.every(function (result) { From e489d648131a56edb89b568790bae0207cbc43ef Mon Sep 17 00:00:00 2001 From: abetomo Date: Wed, 16 Dec 2020 14:48:16 +0900 Subject: [PATCH 2/2] Update .travis.yml https://nodejs.org/ja/about/releases/ --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7789109..acf72d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: node_js node_js: - - "8" - "10" - "12" + - "14"