es-analysis / plato

JavaScript source code visualization, static analysis, and complexity tool
MIT License
4.56k stars 322 forks source link

Display a friendly message if no files are specified (or when no files match the given pattern) #208

Closed akshat1 closed 6 years ago

akshat1 commented 7 years ago

Currently if files are not specified, Plato exits with a stack trace. This PR intends to print a message saying "No files found" along with the Plato usage help.

Changes (using cli.js as reference):

For issue #205

Before

$ bin/plato -d foo
/git/plato/lib/util.js:15
  var lastSlash = files[0].lastIndexOf(path.sep);
                          ^

TypeError: Cannot read property 'lastIndexOf' of undefined
    at Object.exports.findCommonBase (/git/plato/lib/util.js:15:27)
    at Object.exports.inspect (/git/plato/lib/plato.js:87:29)
    at Object.exports.exec (/git/plato/lib/cli.js:53:9)
    at Object.<anonymous> (/git/plato/bin/plato:19:5)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)

Same result with $bin/plato -d foo bar

After

$ bin/plato -d foo
No files found

Usage : plato [options] file1.js file2.js ... fileN.js
  -h, --help
      Display this help text.
  -q, --quiet
      Reduce output to errors only
  -v, --version
      Print the version.
  -x, --exclude : String
      File exclusion regex
  -d, --dir : String *required*
      The output directory
  -r, --recurse
      Recursively search directories
  -l, --jshint : String
      Specify a jshintrc file for JSHint linting
  -e, --eslint : String
      Specify a eslintrc file for ESLint linting
  -t, --title : String
      Title of the report
  -D, --date : String
      Time to use as the report date (seconds, > 9999999999 assumed to be ms)
  -n, --noempty
      Skips empty lines from line count