Skip to content
Permalink
Browse files

Add: Eslint in root files/folders (#177)

  • Loading branch information
VibhorCodecianGupta committed Mar 17, 2020
1 parent d6c3701 commit db6b4ec4121e3a7ca6f6501bb123aa7ae40510bc
Showing with 160 additions and 103 deletions.
  1. +57 −0 npm/test-lint.js
  2. +2 −2 package.json
  3. +1 −1 test/codegen/structure.test.js
  4. +100 −100 test/system/repository.test.js
@@ -0,0 +1,57 @@
#!/usr/bin/env node
require('shelljs/global');

var chalk = require('chalk'),
async = require('async'),
ESLintCLIEngine = require('eslint').CLIEngine,

/**
* The list of source code files / directories to be linted.
*
* @type {Array}
*/
LINT_SOURCE_DIRS = [
'./lib',
'./test',
'./npm/*.js',
'./index.js'
];

module.exports = function (exit) {
// banner line
console.info(chalk.yellow.bold('\nLinting files using eslint...'));

async.waterfall([

/**
* Instantiates an ESLint CLI engine and runs it in the scope defined within LINT_SOURCE_DIRS.
*
* @param {Function} next - The callback function whose invocation marks the end of the lint test run.
* @returns {*}
*/
function (next) {
next(null, (new ESLintCLIEngine()).executeOnFiles(LINT_SOURCE_DIRS));
},

/**
* Processes a test report from the Lint test runner, and displays meaningful results.
*
* @param {Object} report - The overall test report for the current lint test.
* @param {Object} report.results - The set of test results for the current lint run.
* @param {Function} next - The callback whose invocation marks the completion of the post run tasks.
* @returns {*}
*/
function (report, next) {
var errorReport = ESLintCLIEngine.getErrorResults(report.results);
// log the result to CLI
console.info(ESLintCLIEngine.getFormatter()(report.results));
// log the success of the parser if it has no errors
(errorReport && !errorReport.length) && console.info(chalk.green('eslint ok!'));
// ensure that the exit code is non zero in case there was an error
next(Number(errorReport && errorReport.length) || 0);
}
], exit);
};

// ensure we run this script exports if this is a direct stdin.tty run
!module.parent && module.exports(exit);
@@ -14,7 +14,8 @@
"postinstall": "node npm/deepinstall.js",
"deepinstall": "node npm/deepinstall.js",
"boilerplate": "node npm/boilerplate.js",
"cirequirements": "npm/ci-requirements.sh"
"cirequirements": "npm/ci-requirements.sh",
"test-lint": "node npm/test-lint.js"
},
"repository": {
"type": "git",
@@ -48,7 +49,6 @@
"newman": "4.5.7",
"nyc": "14.1.1",
"parse-gitignore": "1.0.1",
"postman-collection": "3.5.1",
"pretty-ms": "3.0.1",
"recursive-readdir": "2.1.0",
"watchify": "3.11.1"
@@ -61,7 +61,7 @@ const expectedOptions = {
default: false,
description: 'Display the requested data without showing the cURL progress meter or error messages'
},
ES6_enabled:{
ES6_enabled: {
name: 'Enable ES6 features',
type: 'boolean',
default: false,
@@ -3,138 +3,138 @@
* content of the file as well. Any change to package.json must be accompanied by valid test case in this spec-sheet.
*/
var _ = require('lodash'),
expect = require('chai').expect,
parseIgnore = require('parse-gitignore');
expect = require('chai').expect,
parseIgnore = require('parse-gitignore');

/* global describe, it */
describe('project repository', function () {
var fs = require('fs');

describe('package.json', function () {
var content,
json;

try {
content = fs.readFileSync('./package.json').toString();
json = JSON.parse(content);
}
catch (e) {
console.error(e);
content = '';
json = {};
}

it('must have readable JSON content', function () {
expect(content).to.be.ok;
expect(json).to.not.eql({});
});
var fs = require('fs');

describe('package.json', function () {
var content,
json;

try {
content = fs.readFileSync('./package.json').toString();
json = JSON.parse(content);
}
catch (e) {
console.error(e);
content = '';
json = {};
}

it('must have readable JSON content', function () {
expect(content).to.be.ok;
expect(json).to.not.eql({});
});

describe('package.json JSON data', function () {
it('must have valid name, description and author', function () {
expect(json).to.have.property('name', 'postman-code-generators');
expect(json).to.have.property('author', 'Postman Labs <help@getpostman.com>');
expect(json).to.have.property('license', 'Apache-2.0');
describe('package.json JSON data', function () {
it('must have valid name, description and author', function () {
expect(json).to.have.property('name', 'postman-code-generators');
expect(json).to.have.property('author', 'Postman Labs <help@getpostman.com>');
expect(json).to.have.property('license', 'Apache-2.0');

expect(json).to.have.property('repository');
expect(json).to.have.property('repository');

expect(json).to.have.property('engines');
expect(json.engines).to.eql({ node: '>=6' });
});
expect(json).to.have.property('engines');
expect(json.engines).to.eql({ node: '>=6' });
});

it('must have a valid version string in form of <major>.<minor>.<revision>', function () {
// eslint-disable-next-line max-len
expect(json.version).to.match(/^((\d+)\.(\d+)\.(\d+))(?:-([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?(?:\+([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?$/);
});
});
it('must have a valid version string in form of <major>.<minor>.<revision>', function () {
// eslint-disable-next-line max-len
expect(json.version).to.match(/^((\d+)\.(\d+)\.(\d+))(?:-([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?(?:\+([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?$/);
});
});


describe.skip('dependencies', function () {
it('must exist', function () {
expect(json.dependencies).to.be.a('object');
});
describe('dependencies', function () {
it('must exist', function () {
expect(json.dependencies).to.be.a('object');
});

it('must point to a valid and precise (no * or ^) semver', function () {
json.dependencies && Object.keys(json.dependencies).forEach(function (item) {
expect(json.dependencies[item]).to.match(new RegExp('^((\\d+)\\.(\\d+)\\.(\\d+))(?:-' +
it('must point to a valid and precise (no * or ^) semver', function () {
json.dependencies && Object.keys(json.dependencies).forEach(function (item) {
expect(json.dependencies[item]).to.match(new RegExp('^((\\d+)\\.(\\d+)\\.(\\d+))(?:-' +
'([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?(?:\\+([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?$'));
});
});
});
});
});

describe('devDependencies', function () {
it('must exist', function () {
expect(json.devDependencies).to.be.a('object');
});
describe('devDependencies', function () {
it('must exist', function () {
expect(json.devDependencies).to.be.a('object');
});

it('must point to a valid and precise (no * or ^) semver', function () {
json.devDependencies && Object.keys(json.devDependencies).forEach(function (item) {
expect(json.devDependencies[item]).to.match(new RegExp('^((\\d+)\\.(\\d+)\\.(\\d+))(?:-' +
it('must point to a valid and precise (no * or ^) semver', function () {
json.devDependencies && Object.keys(json.devDependencies).forEach(function (item) {
expect(json.devDependencies[item]).to.match(new RegExp('^((\\d+)\\.(\\d+)\\.(\\d+))(?:-' +
'([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?(?:\\+([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?$'));
});
});

it.skip('should not overlap dependencies', function () {
var clean = [];
});
});

json.devDependencies && Object.keys(json.devDependencies).forEach(function (item) {
!json.dependencies[item] && clean.push(item);
});
it('should not overlap dependencies', function () {
var clean = [];

expect(Object.keys(json.devDependencies)).to.eql(clean);
});
json.devDependencies && Object.keys(json.devDependencies).forEach(function (item) {
!json.dependencies[item] && clean.push(item);
});

describe('main entry script', function () {
it('must point to a valid file', function (done) {
expect(json.main).to.equal('index.js');
fs.stat(json.main, done);
});
});
expect(Object.keys(json.devDependencies)).to.eql(clean);
});
});

describe('README.md', function () {
it('must exist', function (done) {
fs.stat('./README.md', done);
});
describe('main entry script', function () {
it('must point to a valid file', function (done) {
expect(json.main).to.equal('index.js');
fs.stat(json.main, done);
});
});
});

it('must have readable content', function () {
expect(fs.readFileSync('./README.md').toString()).to.be.ok;
});
describe('README.md', function () {
it('must exist', function (done) {
fs.stat('./README.md', done);
});

describe('LICENSE.md', function () {
it('must exist', function (done) {
fs.stat('./LICENSE.md', done);
});
it('must have readable content', function () {
expect(fs.readFileSync('./README.md').toString()).to.be.ok;
});
});

it('must have readable content', function () {
expect(fs.readFileSync('./LICENSE.md').toString()).to.be.ok;
});
describe('LICENSE.md', function () {
it('must exist', function (done) {
fs.stat('./LICENSE.md', done);
});

describe('.ignore files', function () {
var gitignorePath = '.gitignore',
gitignore = parseIgnore(gitignorePath);
it('must have readable content', function () {
expect(fs.readFileSync('./LICENSE.md').toString()).to.be.ok;
});
});

describe(gitignorePath, function () {
it('must exist', function (done) {
fs.stat(gitignorePath, done);
});
describe('.ignore files', function () {
var gitignorePath = '.gitignore',
gitignore = parseIgnore(gitignorePath);

it('must have valid content', function () {
expect(_.isEmpty(gitignore)).to.not.be.ok;
});
});
describe(gitignorePath, function () {
it('must exist', function (done) {
fs.stat(gitignorePath, done);
});

it('must have valid content', function () {
expect(_.isEmpty(gitignore)).to.not.be.ok;
});
});

describe('.eslintrc', function () {
it('must exist', function (done) {
fs.stat('./.eslintrc', done);
});
});

it('must have readable content', function () {
expect(fs.readFileSync('./.eslintrc').toString()).to.be.ok;
});
describe('.eslintrc', function () {
it('must exist', function (done) {
fs.stat('./.eslintrc', done);
});

it('must have readable content', function () {
expect(fs.readFileSync('./.eslintrc').toString()).to.be.ok;
});
});
});

0 comments on commit db6b4ec

Please sign in to comment.
You can’t perform that action at this time.