From 492cb318054cd8548646d58b14e8ee3275b3b597 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sat, 13 Feb 2021 09:48:09 +0800 Subject: [PATCH 1/8] chore: add recommended JSON extension to ESLint (and Babel) RC files; git-ignore package-lock --- .babelrc => .babelrc.json | 0 .eslintrc => .eslintrc.json | 0 .gitignore | 5 +++-- 3 files changed, 3 insertions(+), 2 deletions(-) rename .babelrc => .babelrc.json (100%) rename .eslintrc => .eslintrc.json (100%) diff --git a/.babelrc b/.babelrc.json similarity index 100% rename from .babelrc rename to .babelrc.json diff --git a/.eslintrc b/.eslintrc.json similarity index 100% rename from .eslintrc rename to .eslintrc.json diff --git a/.gitignore b/.gitignore index 9b16564..e83d733 100755 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,13 @@ coverage dist node_modules +package-lock.json *.log .* -!.babelrc +!.babelrc.json !.editorconfig !.eslintignore -!.eslintrc +!.eslintrc.json !.flowconfig !.gitignore !.npmignore From 241ba29ac7820727551ff621a5385e005c4bcb9f Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sat, 13 Feb 2021 09:48:36 +0800 Subject: [PATCH 2/8] chore(travis): check Node 10, 12, 14; drop 8 --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8b43392..f656e82 100755 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,9 @@ language: node_js node_js: - node - - 8 + - 14 + - 12 + - 10 script: - npm run lint - npm run test From c904e9141cb3af878d10f41ffc327cff46f545da Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sat, 13 Feb 2021 09:49:14 +0800 Subject: [PATCH 3/8] chore(eslint): check for unused disable directives --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 79283cd..90007cb 100644 --- a/package.json +++ b/package.json @@ -67,8 +67,8 @@ "scripts": { "build": "babel ./src --out-dir ./dist --copy-files", "create-readme": "babel-node ./src/bin/index.js ./.README/README.md --output-file ./README.md", - "lint": "eslint ./src ./tests", "test": "mocha \"./tests/**/*.js\" --require @babel/register" + "lint": "eslint --report-unused-disable-directives ./src ./tests", }, "version": "2.5.2" } From 54d52a4b7cb82dcff3fb5fdeb5926ab0ca75cd63 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sat, 13 Feb 2021 09:50:01 +0800 Subject: [PATCH 4/8] test: add `nyc` to test script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 90007cb..ffa3c3f 100644 --- a/package.json +++ b/package.json @@ -67,8 +67,8 @@ "scripts": { "build": "babel ./src --out-dir ./dist --copy-files", "create-readme": "babel-node ./src/bin/index.js ./.README/README.md --output-file ./README.md", - "test": "mocha \"./tests/**/*.js\" --require @babel/register" "lint": "eslint --report-unused-disable-directives ./src ./tests", + "test": "nyc mocha \"./tests/**/*.js\" --require @babel/register" }, "version": "2.5.2" } From 1f785bfcb5de2b613bd8b733b3f935370d32d9c2 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sat, 13 Feb 2021 10:19:47 +0800 Subject: [PATCH 5/8] chore(eslint): update linting devDeps. lint resulting Babel error, and lint accordingly; bump test timeout --- .eslintrc.json | 3 +++ package.json | 6 +++--- src/bin/index.js | 12 ++++++----- src/gitdown.js | 43 ++++++++++++++++----------------------- src/helpers/filesize.js | 10 ++++----- src/helpers/gitinfo.js | 2 +- src/parser.js | 7 +++---- tests/gitdown.js | 2 +- tests/helpers/badge.js | 24 ++++++++++++++++++---- tests/helpers/date.js | 2 +- tests/helpers/filesize.js | 2 +- tests/helpers/variable.js | 4 +--- tests/parser.js | 7 ++----- 13 files changed, 65 insertions(+), 59 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index eb95df2..a7600c7 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,5 +1,8 @@ { "extends": "canonical", + "parserOptions": { + "requireConfigFile": false + }, "rules": { "filenames/match-exported": 0, "import/no-commonjs": 0, diff --git a/package.json b/package.json index ffa3c3f..877d571 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,8 @@ "chai": "^4.2.0", "chai-as-promised": "^7.1.1", "coveralls": "^3.0.9", - "eslint": "~6.8.0", - "eslint-config-canonical": "~19.0.1", + "eslint": "~7.20.0", + "eslint-config-canonical": "~25.8.17", "husky": "^4.2.3", "mocha": "^7.0.1", "nock": "^11.8.2", @@ -68,7 +68,7 @@ "build": "babel ./src --out-dir ./dist --copy-files", "create-readme": "babel-node ./src/bin/index.js ./.README/README.md --output-file ./README.md", "lint": "eslint --report-unused-disable-directives ./src ./tests", - "test": "nyc mocha \"./tests/**/*.js\" --require @babel/register" + "test": "nyc mocha \"./tests/**/*.js\" --require @babel/register --timeout 9000" }, "version": "2.5.2" } diff --git a/src/bin/index.js b/src/bin/index.js index 431c36f..50b45cd 100755 --- a/src/bin/index.js +++ b/src/bin/index.js @@ -1,7 +1,7 @@ #!/usr/bin/env node -const path = require('path'); const fs = require('fs'); +const path = require('path'); const _ = require('lodash'); const yargs = require('yargs'); @@ -11,7 +11,11 @@ const argv = yargs .options({ check: { default: false, - description: 'Checks if the destination file represents the current state of the template. Terminates program with exit status 1 if generating a new document would result in changes of the target document. Terminates program with exit status 0 otherwise (without writng to the destination).', + description: 'Checks if the destination file represents the current ' + + 'state of the template. Terminates program with exit status 1 if ' + + 'generating a new document would result in changes of the target ' + + 'document. Terminates program with exit status 0 otherwise (without ' + + 'writng to the destination).', type: 'boolean', }, force: { @@ -41,7 +45,7 @@ const argv = yargs try { fs.accessSync(inputFile, fs.constants.W_OK); - } catch (error) { + } catch { // eslint-disable-next-line no-console console.log('inputFile', inputFile); @@ -72,7 +76,6 @@ const main = async () => { const resolvedInputFile = path.resolve(process.cwd(), inputFile); const resolvedOutputFile = path.resolve(process.cwd(), outputFile); - // eslint-disable-next-line global-require const Gitdown = require('..'); const gitdown = Gitdown.readFile(resolvedInputFile); @@ -86,7 +89,6 @@ const main = async () => { // eslint-disable-next-line no-console console.error('Gitdown destination file does not represent the current state of the template.'); - // eslint-disable-next-line no-process-exit process.exit(1); } diff --git a/src/gitdown.js b/src/gitdown.js index bcd580d..93c652d 100644 --- a/src/gitdown.js +++ b/src/gitdown.js @@ -2,14 +2,14 @@ const Gitdown = {}; const fs = require('fs'); const path = require('path'); const Promise = require('bluebird'); -const _ = require('lodash'); -const marked = require('marked'); const Deadlink = require('deadlink'); const getUrls = require('get-urls'); +const _ = require('lodash'); const MarkdownContents = require('markdown-contents'); +const marked = require('marked'); const StackTrace = require('stack-trace'); -const gitinfo = require('./helpers/gitinfo.js'); const contents = require('./helpers/contents.js'); +const gitinfo = require('./helpers/gitinfo.js'); const Parser = require('./parser.js'); /** @@ -29,24 +29,19 @@ Gitdown.read = (input) => { * * @returns {Promise} */ - gitdown.get = () => { - return parser - .play(input) - .then((state) => { - let markdown; + gitdown.get = async () => { + const state = await parser.play(input); - markdown = state.markdown; + let markdown; + markdown = state.markdown; - if (gitdown.getConfig().headingNesting.enabled) { - markdown = Gitdown.nestHeadingIds(markdown); - } + if (gitdown.getConfig().headingNesting.enabled) { + markdown = Gitdown.nestHeadingIds(markdown); + } - return gitdown - .resolveURLs(markdown) - .then(() => { - return markdown.replace(//g, ''); - }); - }); + await gitdown.resolveURLs(markdown); + + return markdown.replace(//g, ''); }; /** @@ -55,12 +50,10 @@ Gitdown.read = (input) => { * @param {string} fileName * @returns {Promise} */ - gitdown.writeFile = (fileName) => { - return gitdown - .get() - .then((outputString) => { - return fs.writeFileSync(fileName, outputString); - }); + gitdown.writeFile = async (fileName) => { + const outputString = await gitdown.get(); + + return fs.writeFileSync(fileName, outputString); }; /** @@ -341,7 +334,7 @@ Gitdown.nestHeadingIds.iterateTree = (tree, callback, index = 1) => { nextIndex = index; tree.forEach((article) => { - // eslint-disable-next-line callback-return + // eslint-disable-next-line promise/prefer-await-to-callbacks callback(nextIndex++, article); if (article.descendants) { diff --git a/src/helpers/filesize.js b/src/helpers/filesize.js index 2356a7c..f811cab 100644 --- a/src/helpers/filesize.js +++ b/src/helpers/filesize.js @@ -5,18 +5,16 @@ const formatFileSize = require('filesize'); const helper = {}; -helper.compile = (config = {}) => { +helper.compile = async (config = {}) => { config.gzip = config.gzip || false; if (!config.file) { return Promise.reject(new Error('config.file must be provided.')); } - return helper - .file(config.file, config.gzip) - .then((fileSize) => { - return helper.format(fileSize); - }); + const fileSize = await helper.file(config.file, config.gzip); + + return helper.format(fileSize); }; /** diff --git a/src/helpers/gitinfo.js b/src/helpers/gitinfo.js index 58d6078..2bf5b77 100644 --- a/src/helpers/gitinfo.js +++ b/src/helpers/gitinfo.js @@ -1,6 +1,6 @@ const helper = {}; -const _ = require('lodash'); const createGitinfo = require('gitinfo').default; +const _ = require('lodash'); helper.compile = (config, context) => { const parserConfig = context.gitdown.getConfig().gitinfo; diff --git a/src/parser.js b/src/parser.js index 49d8960..bef6c36 100644 --- a/src/parser.js +++ b/src/parser.js @@ -1,7 +1,7 @@ const Path = require('path'); -const _ = require('lodash'); const Promise = require('bluebird'); const glob = require('glob'); +const _ = require('lodash'); const Locator = require('./locator.js'); /** @@ -83,7 +83,7 @@ const Parser = (gitdown) => { try { command = JSON.parse(match); - } catch (error) { + } catch { throw new Error('Invalid Gitdown JSON ("' + match + '").'); } @@ -113,7 +113,7 @@ const Parser = (gitdown) => { }); outputMarkdown = outputMarkdown.replace(/⊂⊂I:(\d+)⊃⊃/g, (match, p1) => { - return ignoreSection[parseInt(p1, 10) - 1]; + return ignoreSection[Number.parseInt(p1, 10) - 1]; }); return { @@ -178,7 +178,6 @@ const Parser = (gitdown) => { */ parser.loadHelpers = () => { glob.sync(Path.resolve(__dirname, './helpers/*.js')).forEach((helper) => { - // eslint-disable-next-line global-require parser.registerHelper(Path.basename(helper, '.js'), require(helper)); }); }; diff --git a/tests/gitdown.js b/tests/gitdown.js index 7d03e41..a311592 100644 --- a/tests/gitdown.js +++ b/tests/gitdown.js @@ -3,8 +3,8 @@ const fs = require('fs'); const path = require('path'); const expect = require('chai').expect; -const requireNew = require('require-uncached'); const nock = require('nock'); +const requireNew = require('require-uncached'); const sinon = require('sinon'); describe('Gitdown', () => { diff --git a/tests/helpers/badge.js b/tests/helpers/badge.js index dc6940f..bce4e9a 100644 --- a/tests/helpers/badge.js +++ b/tests/helpers/badge.js @@ -122,7 +122,11 @@ describe('Parser.helpers.badge', () => { it('returns markdown for the david badge', () => { const badge = helper.compile({name: 'david-dev'}, gitinfoContext); - expect(badge).to.equal('[![Development Dependency Status](https://img.shields.io/david/dev/a/b.svg?style=flat-square)](https://david-dm.org/a/b#info=devDependencies)'); + expect(badge).to.equal( + '[![Development Dependency Status](' + + 'https://img.shields.io/david/dev/a/b.svg?style=flat-square' + + ')](https://david-dm.org/a/b#info=devDependencies)', + ); }); }); describe('travis', () => { @@ -144,12 +148,20 @@ describe('Parser.helpers.badge', () => { it('returns markdown for the codeclimate gpa badge', () => { const badge = helper.compile({name: 'codeclimate-gpa'}, gitinfoContext); - expect(badge).to.equal('[![Code Climate GPA](https://img.shields.io/codeclimate/github/a/b.svg?style=flat-square)](https://codeclimate.com/github/a/b)'); + expect(badge).to.equal( + '[![Code Climate GPA]' + + '(https://img.shields.io/codeclimate/github/a/b.svg?style=flat-square' + + ')](https://codeclimate.com/github/a/b)', + ); }); it('returns markdown for the codeclimate coverage badge', () => { const badge = helper.compile({name: 'codeclimate-coverage'}, gitinfoContext); - expect(badge).to.equal('[![Code Climate Coverage](https://img.shields.io/codeclimate/coverage/github/a/b.svg?style=flat-square)](https://codeclimate.com/github/a/b)'); + expect(badge).to.equal( + '[![Code Climate Coverage](' + + 'https://img.shields.io/codeclimate/coverage/github/a/b.svg?style=flat-square' + + ')](https://codeclimate.com/github/a/b)', + ); }); }); @@ -157,7 +169,11 @@ describe('Parser.helpers.badge', () => { it('returns markdown for the AppVeyor badge', () => { const badge = helper.compile({name: 'appveyor'}, gitinfoContext); - expect(badge).to.equal('[![AppVeyor build status](https://img.shields.io/appveyor/ci/a/b/c.svg?style=flat-square)](https://ci.appveyor.com/project/a/b/branch/c)'); + expect(badge).to.equal( + '[![AppVeyor build status](' + + 'https://img.shields.io/appveyor/ci/a/b/c.svg?style=flat-square' + + ')](https://ci.appveyor.com/project/a/b/branch/c)', + ); }); }); }); diff --git a/tests/helpers/date.js b/tests/helpers/date.js index 3afc1d7..5a095ab 100644 --- a/tests/helpers/date.js +++ b/tests/helpers/date.js @@ -8,7 +8,7 @@ describe('Parser.helpers.date', () => { helper = requireNew('../../src/helpers/date.js'); }); it('returns current UNIX timestamp', () => { - expect(helper.compile()).to.equal(String(Math.floor(new Date().getTime() / 1000))); + expect(helper.compile()).to.equal(String(Math.floor(Date.now() / 1_000))); }); it('uses format parameter to adjust the format', () => { expect(helper.compile({format: 'YYYY'})).to.equal(String(new Date().getUTCFullYear())); diff --git a/tests/helpers/filesize.js b/tests/helpers/filesize.js index 6f32a62..63d579b 100644 --- a/tests/helpers/filesize.js +++ b/tests/helpers/filesize.js @@ -63,7 +63,7 @@ describe('Parser.helpers.filesize', () => { }); describe('.format(size)', () => { it('returns file size as a human readable string', () => { - const result = helper.format(1024); + const result = helper.format(1_024); expect(result).to.equal('1 KB'); }); diff --git a/tests/helpers/variable.js b/tests/helpers/variable.js index 4e0f4f5..ecd37ea 100644 --- a/tests/helpers/variable.js +++ b/tests/helpers/variable.js @@ -12,9 +12,7 @@ describe('Parser.helpers.variable', () => { getConfig: () => { return { variable: { - scope: { - - }, + scope: {}, }, }; }, diff --git a/tests/parser.js b/tests/parser.js index 337324f..3c4c36d 100644 --- a/tests/parser.js +++ b/tests/parser.js @@ -1,9 +1,9 @@ /* eslint-disable max-nested-callbacks */ const chai = require('chai'); -const sinon = require('sinon'); -const requireNew = require('require-uncached'); const chaiAsPromised = require('chai-as-promised'); +const requireNew = require('require-uncached'); +const sinon = require('sinon'); chai.use(chaiAsPromised); @@ -78,13 +78,10 @@ describe('Gitdown.Parser', () => { }); describe('Parser.helpers', () => { - // eslint-disable-next-line global-require const glob = require('glob'); - // eslint-disable-next-line global-require const path = require('path'); glob.sync('./../src/helpers/*.js').forEach((helperName) => { - // eslint-disable-next-line global-require const helper = require(helperName); describe(path.basename(helperName, '.js'), () => { From ca0e4e4e1f76e1bf527c3402e4370696f92cce23 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sat, 13 Feb 2021 10:20:33 +0800 Subject: [PATCH 6/8] chore: add `engines` with Node >= 10 --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 877d571..6e637fd 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,9 @@ "type": "git", "url": "https://github.com/gajus/gitdown" }, + "engines": { + "node": ">=10" + }, "scripts": { "build": "babel ./src --out-dir ./dist --copy-files", "create-readme": "babel-node ./src/bin/index.js ./.README/README.md --output-file ./README.md", From 36221a4e27497c87c8a9033efb16f9a93970b735 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sat, 13 Feb 2021 10:23:08 +0800 Subject: [PATCH 7/8] chore: add .ncurc.js to temporarily avoid husky update --- .gitignore | 1 + .ncurc.js | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 .ncurc.js diff --git a/.gitignore b/.gitignore index e83d733..6b3ec36 100755 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ package-lock.json !.npmignore !.travis.yml !.README +!.ncurc.js diff --git a/.ncurc.js b/.ncurc.js new file mode 100644 index 0000000..6baf1a8 --- /dev/null +++ b/.ncurc.js @@ -0,0 +1,6 @@ +'use strict'; + +module.exports = { + // Todo [husky@>=6]: Might be MIT again + reject: ['husky'], +}; From 0674cc901e2667646d00e9f95a602b14bdb2f26e Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sat, 13 Feb 2021 10:33:27 +0800 Subject: [PATCH 8/8] chore: update vulnerable dep. get-urls; update other deps (filesize, jsonfile, lodash, marked, moment, yargs); update devDeps. --- README.md | 2 +- package.json | 40 ++++++++++++++++++++-------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 90d5aab..9c149a2 100644 --- a/README.md +++ b/README.md @@ -500,7 +500,7 @@ Returns file size formatted in human friendly format. Generates: ```markdown -8.57 KB +8.47 KB 2.54 KB ``` diff --git a/package.json b/package.json index 6e637fd..4e7a30f 100644 --- a/package.json +++ b/package.json @@ -8,39 +8,39 @@ "dependencies": { "bluebird": "^3.7.2", "deadlink": "^1.1.3", - "filesize": "^6.0.1", - "get-urls": "^9.2.0", + "filesize": "^6.1.0", + "get-urls": "^10.0.0", "gitinfo": "^2.4.0", "glob": "^7.1.6", - "jsonfile": "^5.0.0", - "lodash": "^4.17.15", + "jsonfile": "^6.1.0", + "lodash": "^4.17.20", "markdown-contents": "^1.0.11", - "marked": "^0.8.0", - "moment": "^2.24.0", + "marked": "^2.0.0", + "moment": "^2.29.1", "stack-trace": "^0.0.10", - "yargs": "^15.1.0" + "yargs": "^16.2.0" }, "description": "Github markdown preprocessor.", "devDependencies": { - "@babel/cli": "^7.8.4", - "@babel/core": "^7.8.4", - "@babel/node": "^7.8.4", - "@babel/plugin-transform-flow-strip-types": "^7.8.3", - "@babel/preset-env": "^7.8.4", - "@babel/register": "^7.8.3", + "@babel/cli": "^7.12.16", + "@babel/core": "^7.12.16", + "@babel/node": "^7.12.16", + "@babel/plugin-transform-flow-strip-types": "^7.12.13", + "@babel/preset-env": "^7.12.16", + "@babel/register": "^7.12.13", "babel-plugin-istanbul": "^6.0.0", - "chai": "^4.2.0", + "chai": "^4.3.0", "chai-as-promised": "^7.1.1", - "coveralls": "^3.0.9", + "coveralls": "^3.1.0", "eslint": "~7.20.0", "eslint-config-canonical": "~25.8.17", "husky": "^4.2.3", - "mocha": "^7.0.1", - "nock": "^11.8.2", - "nyc": "^15.0.0", + "mocha": "^8.3.0", + "nock": "^13.0.7", + "nyc": "^15.1.0", "require-uncached": "^2", - "semantic-release": "^17.0.3", - "sinon": "^8.1.1" + "semantic-release": "^17.3.9", + "sinon": "^9.2.4" }, "husky": { "hooks": {