Skip to content

Commit

Permalink
Merge pull request #40 from abetomo/feature/upgrade_standard_to_16
Browse files Browse the repository at this point in the history
Upgrade standard to 16
  • Loading branch information
zeke authored Aug 30, 2021
2 parents cef5c5b + e489d64 commit c7fe72f
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- "8"
- "10"
- "12"
- "14"
24 changes: 12 additions & 12 deletions cli.js
Original file line number Diff line number Diff line change
@@ -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/**',
Expand All @@ -19,7 +19,7 @@ var patterns = [
'!bundle.js'
]

var cwd
let cwd

program
.version(require('./package.json').version)
Expand All @@ -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) {
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
16 changes: 8 additions & 8 deletions lib/codeBlockUtils.js
Original file line number Diff line number Diff line change
@@ -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*$/, '')

Expand Down
4 changes: 2 additions & 2 deletions lib/formatter.js
Original file line number Diff line number Diff line change
@@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion lib/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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",
Expand Down
23 changes: 13 additions & 10 deletions tests/index.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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) {
Expand Down

0 comments on commit c7fe72f

Please sign in to comment.