From 99134f6e09d550c2bd8aae1d8eb544f5f80dc54a Mon Sep 17 00:00:00 2001 From: Anatoly Bubenkov Date: Mon, 15 Jan 2018 16:24:34 +0100 Subject: [PATCH] Support `--shallow` argument for `lint` command. Closes #956 --- __tests__/bin.js | 15 ++++++++++++++- .../fixture/lint/lint.input.dependency.js | 19 +++++++++++++++++++ __tests__/fixture/lint/lint.input.shallow.js | 7 +++++++ src/commands/lint.js | 11 +++++++---- 4 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 __tests__/fixture/lint/lint.input.dependency.js create mode 100644 __tests__/fixture/lint/lint.input.shallow.js diff --git a/__tests__/bin.js b/__tests__/bin.js index 277365442..d636af9a4 100644 --- a/__tests__/bin.js +++ b/__tests__/bin.js @@ -185,7 +185,11 @@ describe('lint command', function() { try { await documentation(['lint fixture/lint/lint.input.js'], {}, false); } catch (err) { - var data = err.stderr.toString().split('\n').slice(2).join('\n'); + var data = err.stderr + .toString() + .split('\n') + .slice(2) + .join('\n'); expect(data).toMatchSnapshot(); } }); @@ -224,6 +228,15 @@ describe('lint command', function() { expect(err.code > 0).toBeTruthy(); } }); + + test('generates lint output with shallow', async function() { + const data = await documentation( + ['lint fixture/lint/lint.input.shallow.js --shallow'], + {}, + false + ); + expect(data).toBe(''); + }); }); test('given no files', async function() { diff --git a/__tests__/fixture/lint/lint.input.dependency.js b/__tests__/fixture/lint/lint.input.dependency.js new file mode 100644 index 000000000..b4ff5d4d8 --- /dev/null +++ b/__tests__/fixture/lint/lint.input.dependency.js @@ -0,0 +1,19 @@ +/** + * @param {String} foo bar + * @returns {object} bad object return type + * @type {Array} bad object type + * @memberof notfound + */ + +/** + * @param {String} baz bar + * @property {String} bad property + * @private + */ + +/** + * @param {number} c explicit but not found + */ +function add(a, b) {} + +module.exports.add = add; diff --git a/__tests__/fixture/lint/lint.input.shallow.js b/__tests__/fixture/lint/lint.input.shallow.js new file mode 100644 index 000000000..aa404f37e --- /dev/null +++ b/__tests__/fixture/lint/lint.input.shallow.js @@ -0,0 +1,7 @@ +var dep = require('./lint.input.dependency'); + +/** + * @param {string} a + * @param {boolean} b + */ +function add(a, b) {} diff --git a/src/commands/lint.js b/src/commands/lint.js index 3e465cc9c..a58027ab9 100644 --- a/src/commands/lint.js +++ b/src/commands/lint.js @@ -1,14 +1,17 @@ /* @flow */ -var documentation = require('../'); -var fs = require('fs'); -var path = require('path'); +var documentation = require('../'), + sharedOptions = require('./shared_options'), + fs = require('fs'), + path = require('path'); /* eslint no-console: 0 */ module.exports.command = 'lint [input..]'; module.exports.description = 'check for common style and uniformity mistakes'; -module.exports.builder = {}; +module.exports.builder = { + shallow: sharedOptions.sharedInputOptions.shallow +}; /** * Wrap around the documentation.lint method and add the additional