bundle-linter usage

ateebshaik
Participant III

HI,

Would like to know how to use static code analysis tool bundle-linter.

I have downloaded the sample bundle and code from git from below link

bundle-linter

Can someone tell me how to execute sample.js file from the code in the link

Thanks

0 12 726
12 REPLIES 12

Not applicable

Absolutely. The sample config file should be fully functional, you need only replace certain values to point to your bundle by modifying the path to point to the directory that contains your apiproxy folder.

var bl = require("./package/bundleLinter.js");

var configuration = {
    debug: true,
    "source": {
        "type": "filesystem",
        "path": "../sampleProxy",
    },
    //plugins: ['checkFileName.js']
};

bl.lint(configuration);

From there you simply execute the sample.js file with node as in:

davidwallen-macbookpro:src davidwallen$ node ./sample.js

A common issue is the path not being resolvable from where you are executing bundle-linter - in that case you might try and absolute path instead of the relative path in the example.

+ npm install in the package directory to install all the dependencies.
The sample.js has a path issue, make sure you have the right path to your sampleproxy. @Mohammad Ateeb Shaik

This is the error i am getting

module.js:471 throw err; ^ Error: Cannot find module 'D:\Source Code\carnival.api\src\gateway\carnival\api- bundles\bundle-linter-master\sample.js' at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:390:7) at startup (bootstrap_node.js:150:9) at bootstrap_node.js:505:3

I have already installed apigee-bundle-linter module

Run it from the place where you have sample.js, cd /Bundle-linter/src @Mohammad Ateeb Shaik

Tried running from the src directory i got the below error

r\src\package\Bundle.js:68 process.chdir(config.source.path); ^ Error: ENOENT: no such file or directory, uv_chdir at Error (native) at Object.filesystem (D:\Source Code\carnival.api\src\gateway\carnival\api-b undles\bundle-linter-master\src\package\Bundle.js:68:17) at Object.config (D:\Source Code\carnival.api\src\gateway\carnival\api-bundl es\bundle-linter-master\src\package\Bundle.js:65:33) at new Bundle (D:\Source Code\carnival.api\src\gateway\carnival\api-bundles\ bundle-linter-master\src\package\Bundle.js:101:10) at Object.lint (D:\Source Code\carnival.api\src\gateway\carnival\api-bundles \bundle-linter-master\src\package\bundleLinter.js:50:22) at Object.<anonymous> (D:\Source Code\carnival.api\src\gateway\carnival\api- bundles\bundle-linter-master\src\sample.js:12:4) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12)

Also in the sample.js file i have given the absolute path for the proxy folder

@Mohammad Ateeb Shaik, @Dallen,

I found that using "npm install -g apigeelint" on the npm package here does not create the main.js file correctly.

I modified /usr/local/lib/node_modules/apigeelint/main.js to:

#!/usr/bin/env node
var bl = require("./lib/package/bundleLinter.js"),
util = require("util");

var program = require('commander');
program
  .version('0.0.1')
  .option('-s --path <path>','Path of the proxies')
  .parse(process.argv);

console.log('path', program.path);

var configuration = {
    debug: true,
    "source": {
        "type": "filesystem",
        "path": program.path,
    },
    //plugins: ['bundleStructure.js']
};

console.log(util.inspect(bl.lint(configuration), { showHidden: false, depth: 9, maxArrayLength: 100 })); 

Then I can just run as: "apigeelint --path samples/apiproxy"

Working now, thanks to @Maruti Chand's quick work.

Thanks for pointing out the bug and feedback!! @Kurt Kanaskie

Not applicable

Thanks @Kurt Kanaskie for pointing out.
We published the apigeelint last week and there is no need to write a sample.js to run anymore.

Example:

apigeelint --help
  Usage: apigeelint [options]
  Options:
    -h, --help        output usage information
    -V, --version     output the version number
    -s --path <path>  Path of the proxies
example
apigeelint -s No-Target
apigeelint --version
0.1.6

@Maruti Chand Within Maven, is there a way to control the report format and save it under a specific directory? Can you share a sample if there is one.

@rakeshapi , Answers are strictly for answers. Please use comments to ask a question / give feedback / need any clarifications. Thank you for keep the community clean. Converting same to comment.