Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

finn-js-code-style

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

finn-js-code-style - npm Package Compare versions

Comparing version 4.1.2 to 4.2.0

.tern-project

75

lib/cli.js

@@ -5,10 +5,19 @@ var path = require('path');

var jshintStylish = require(require('jshint-stylish'));
var JSHINTRC = '.jshintrc';
var NODE_MODULES = __dirname + '/../node_modules';
var USAGE = [
'Usage: finn-js-code-style <file | dir>...',
'Use the .jshintrc file for jshint config (should \"extend\": \"./node_modules/finn-js-code-style/.jshintrc\")',
'Use the .jshintignore to exclude files or folders'
'Usage:',
'\tfinn-js-code-style [options] <file | dir>...',
'',
'Use the .jshintrc file for jshint config (should "extends": "./node_modules/finn-js-code-style/.jshintrc")',
'Use the .jshintignore to exclude files or folders',
'',
'Options:',
'\t--fail : exits with code 1 when errors are generated',
'\t--help : usage info'
].join('\n');
var jshintRcPath = path.join(process.cwd(), JSHINTRC);
function isProjectRoot () {

@@ -18,13 +27,47 @@ return fs.existsSync( path.join(process.cwd(), 'package.json') );

module.exports = function (args) {
var cmd, result, report;
var currentDir = process.cwd();
var jshintRc = path.join(currentDir, JSHINTRC);
var jsonReporter = '--reporter ' + path.join(NODE_MODULES, 'jshint-json', 'json.js');
function isRuntimeError(execResult) {
return execResult.code === 1 && execResult.output;
}
if (!fs.existsSync(jshintRc) && isProjectRoot()) {
function isStyleError(execResult) {
return execResult.code === 2 && execResult.output;
}
function isError(execResult) {
return execResult.code !== 0;
}
function excludeOpts(args) {
return args.filter(function(arg) {
return arg.indexOf('--') === -1;
});
}
function validateLocalJsHintRc() {
if (!fs.existsSync(jshintRcPath) && isProjectRoot()) {
console.log('No .jshintrc found. Creating...');
fs.writeFileSync(jshintRc, '{\n \"extends\": \"./node_modules/finn-js-code-style/.jshintrc\"\n}\n');
fs.writeFileSync(jshintRcPath, '{\n \"extends\": \"./node_modules/finn-js-code-style/.jshintrc\"\n}\n');
}
}
function displayResult(result, cmd) {
var report;
if (isRuntimeError(result)) {
console.error('jshint command failed, runned with: ' + cmd);
console.error(result.output);
} else if (isStyleError(result)) {
report = JSON.parse(result.output);
jshintStylish.reporter(report.result, report.data);
}
}
module.exports = function cli(args) {
var cmd, result;
var jsonReporter = '--reporter ' + path.join(NODE_MODULES, 'jshint-json', 'json.js');
var shouldFail = args[0] === '--fail';
var filesToHint = excludeOpts(args).join(' ');
validateLocalJsHintRc();
if (args.length === 0 || args[0] === '--help') {

@@ -35,12 +78,10 @@ console.log(USAGE);

cmd = path.join(NODE_MODULES, '.bin', 'jshint') + ' ' + jsonReporter + ' ' + args.join(' ');
cmd = path.join(NODE_MODULES, '.bin', 'jshint') + ' ' + jsonReporter + ' ' + filesToHint;
result = exec(cmd, {silent: true});
if (result.code === 1 && result.output) {
console.log('jshint command used: ' + cmd);
console.log(result.output);
} else if (result.code === 2 && result.output) {
report = JSON.parse(result.output);
jshintStylish.reporter(report.result, report.data);
displayResult(result, cmd);
if (isError(result) && shouldFail) {
process.exit(1);
}
};
{
"name": "finn-js-code-style",
"version": "4.1.2",
"version": "4.2.0",
"description": "Config files for FINN JavaScript style",

@@ -5,0 +5,0 @@ "main": "lib/cli.js",

@@ -18,4 +18,9 @@ # FINN.no JavaScript code style

finn-js-code-style <file | dir>...
finn-js-code-style [options] <file | dir>...
### Options
* `--help` Usage info
* `--fail` Exit with code 1 when errors are generated
## Config

@@ -22,0 +27,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc