Skip to content

Commit

Permalink
Update dependencies (#105)
Browse files Browse the repository at this point in the history
* Update dependencies

* Update Config.test.js

* Update Config.test.js
  • Loading branch information
tclindner authored Feb 16, 2019
1 parent 5377c2d commit 6d2b71a
Show file tree
Hide file tree
Showing 65 changed files with 413 additions and 496 deletions.
4 changes: 1 addition & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module.exports = {
clearMocks: true,
collectCoverage: true,
collectCoverageFrom: [
'src/**/*.js'
],
collectCoverageFrom: ['src/**/*.js'],
coverageThreshold: {
global: {
branches: 92,
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"test:ci": "jest --runInBand"
},
"dependencies": {
"ajv": "^6.8.1",
"ajv": "^6.9.1",
"chalk": "^2.4.2",
"glob": "^7.1.3",
"ignore": "^5.0.5",
Expand All @@ -49,13 +49,15 @@
"validator": "^10.11.0"
},
"devDependencies": {
"eslint": "^5.13.0",
"eslint-config-tc": "^5.2.0",
"eslint": "^5.14.0",
"eslint-config-tc": "^6.0.0",
"eslint-formatter-pretty": "^2.1.1",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-prettier": "^3.0.1",
"figures": "^2.0.0",
"jest": "^24.1.0",
"npm-package-json-lint-config-default": "^2.0.0"
"npm-package-json-lint-config-default": "^2.0.0",
"prettier": "^1.16.4"
},
"engines": {
"node": ">=6.0.0",
Expand Down
77 changes: 38 additions & 39 deletions src/CLIEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,24 @@ const noIssues = 0;
* @returns {ResultCounts} Counts object
* @private
*/
const aggregateCountsPerFile = (issues) => {
const aggregateCountsPerFile = issues => {
const incrementOne = 1;

return issues.reduce((counts, issue) => {
if (issue.severity === 'error') {
counts.errorCount += incrementOne;
} else {
counts.warningCount += incrementOne;
}
return issues.reduce(
(counts, issue) => {
if (issue.severity === 'error') {
counts.errorCount += incrementOne;
} else {
counts.warningCount += incrementOne;
}

return counts;
}, {
errorCount: 0,
warningCount: 0
});
return counts;
},
{
errorCount: 0,
warningCount: 0
}
);
};

/**
Expand All @@ -83,16 +86,19 @@ const aggregateCountsPerFile = (issues) => {
* @returns {ResultCounts} Counts object
* @private
*/
const aggregateOverallCounts = (results) => {
return results.reduce((counts, result) => {
counts.errorCount += result.errorCount;
counts.warningCount += result.warningCount;

return counts;
}, {
errorCount: 0,
warningCount: 0
});
const aggregateOverallCounts = results => {
return results.reduce(
(counts, result) => {
counts.errorCount += result.errorCount;
counts.warningCount += result.warningCount;

return counts;
},
{
errorCount: 0,
warningCount: 0
}
);
};

/**
Expand Down Expand Up @@ -152,7 +158,7 @@ const processPackageJsonFile = (fileName, configHelper, linter) => {
* @returns {boolean} True if error, false if warning.
* @private
*/
const isIssueAnError = (issue) => {
const isIssueAnError = issue => {
return issue.severity === 'error';
};

Expand All @@ -165,9 +171,7 @@ const isIssueAnError = (issue) => {
*/
const getIgnorer = (cwd, options) => {
const ignoreFilePath = options.ignorePath || DEFAULT_IGNORE_FILENAME;
const absoluteIgnoreFilePath = path.isAbsolute(ignoreFilePath)
? ignoreFilePath
: path.resolve(cwd, ignoreFilePath);
const absoluteIgnoreFilePath = path.isAbsolute(ignoreFilePath) ? ignoreFilePath : path.resolve(cwd, ignoreFilePath);
let ignoreText = '';

try {
Expand All @@ -192,10 +196,10 @@ const getFileList = (patterns, options) => {
const cwd = (options && options.cwd) || process.cwd();

// step 1 - filter out empty entries
const filteredPatterns = patterns.filter((pattern) => pattern.length);
const filteredPatterns = patterns.filter(pattern => pattern.length);

// step 2 - convert directories to globs
const globPatterns = filteredPatterns.map((pattern) => {
const globPatterns = filteredPatterns.map(pattern => {
const suffix = '/**/package.json';

let newPath = pattern;
Expand Down Expand Up @@ -226,7 +230,7 @@ const getFileList = (patterns, options) => {
const addedFiles = new Set();
const ignorer = getIgnorer(cwd, options);

globPatterns.forEach((pattern) => {
globPatterns.forEach(pattern => {
const file = path.resolve(cwd, pattern);

if (fs.existsSync(file) && fs.statSync(file).isFile()) {
Expand All @@ -248,9 +252,9 @@ const getFileList = (patterns, options) => {

// remove node_module package.json files. Manually doing this instead of using glob ignore
// because of https://github.com/isaacs/node-glob/issues/309
globFiles = globFiles.filter((globFile) => !globFile.includes('node_modules'));
globFiles = globFiles.filter(globFile => !globFile.includes('node_modules'));

globFiles.forEach((globFile) => {
globFiles.forEach(globFile => {
const filePath = path.resolve(cwd, globFile);

if (addedFiles.has(filePath) || ignorer.ignores(path.relative(cwd, filePath))) {
Expand All @@ -271,14 +275,12 @@ const getFileList = (patterns, options) => {
* @class
*/
class CLIEngine {

/**
* constructor
* @param {CLIEngineOptions} passedOptions The options for the CLIEngine.
* @constructor
*/
constructor(passedOptions) {

const options = Object.assign(Object.create(null), {cwd: process.cwd()}, passedOptions);

this.options = options;
Expand Down Expand Up @@ -310,7 +312,7 @@ class CLIEngine {
static getErrorResults(results) {
const filtered = [];

results.forEach((result) => {
results.forEach(result => {
const filteredIssues = result.issues.filter(isIssueAnError);

if (filteredIssues.length > noIssues) {
Expand All @@ -334,7 +336,7 @@ class CLIEngine {
*/
executeOnPackageJsonFiles(patterns) {
const fileList = getFileList(patterns, this.options);
const results = fileList.map((filePath) => processPackageJsonFile(filePath, this.config, this.linter));
const results = fileList.map(filePath => processPackageJsonFile(filePath, this.config, this.linter));
const stats = aggregateOverallCounts(results);

return {
Expand All @@ -355,9 +357,7 @@ class CLIEngine {
executeOnPackageJsonObject(packageJsonObj, filename) {
const results = [];

const resolvedFilename = filename && !path.isAbsolute(filename)
? path.resolve(this.options.cwd, filename)
: filename;
const resolvedFilename = filename && !path.isAbsolute(filename) ? path.resolve(this.options.cwd, filename) : filename;

results.push(processPackageJsonObject(packageJsonObj, this.config, resolvedFilename, this.linter));

Expand All @@ -380,7 +380,6 @@ class CLIEngine {
getConfigForFile(filePath) {
return this.config.get(filePath);
}

}

module.exports = CLIEngine;
17 changes: 12 additions & 5 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const getProjectDir = () => path.resolve(__dirname, '../../../');
* @class
*/
class Config {

/**
* Constructor
* @param {Object} providedOptions Options object
Expand Down Expand Up @@ -118,9 +117,19 @@ class Config {
config = ConfigFile.loadFromPackageJson(pkgJsonFilePath, this);
}

if (this.useConfigFiles && Object.keys(config.rules).length === noRules && fs.existsSync(jsonRcFilePath) && fs.statSync(jsonRcFilePath).isFile()) {
if (
this.useConfigFiles &&
Object.keys(config.rules).length === noRules &&
fs.existsSync(jsonRcFilePath) &&
fs.statSync(jsonRcFilePath).isFile()
) {
config = ConfigFile.load(jsonRcFilePath, this);
} else if (this.useConfigFiles && Object.keys(config.rules).length === noRules && fs.existsSync(javaScriptConfigFilePath) && fs.statSync(javaScriptConfigFilePath).isFile()) {
} else if (
this.useConfigFiles &&
Object.keys(config.rules).length === noRules &&
fs.existsSync(javaScriptConfigFilePath) &&
fs.statSync(javaScriptConfigFilePath).isFile()
) {
config = ConfigFile.load(javaScriptConfigFilePath, this);
}

Expand Down Expand Up @@ -181,7 +190,6 @@ class Config {
if (Object.keys(personalConfig).length) {
finalConfig = Object.assign({}, personalConfig);
} else {

// No config found in all locations
const relativeFilePath = `./${path.relative(this.options.cwd, filePath)}`;

Expand All @@ -192,7 +200,6 @@ class Config {
// Step 5: return final config
return finalConfig;
}

}

module.exports = Config;
2 changes: 0 additions & 2 deletions src/LintIssue.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const chalk = require('chalk');
const logSymbols = require('log-symbols');

class LintIssue {

/**
* constructor
* @param {String} lintId Unique, lowercase, hyphen-separate name for the lint
Expand All @@ -29,7 +28,6 @@ class LintIssue {

return `${logSymbol} ${formattedLintId} - node: ${formattedNode} - ${formattedMessage}`;
}

}

module.exports = LintIssue;
5 changes: 2 additions & 3 deletions src/NpmPackageJsonLint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const Rules = require('./Rules');
const pkg = require('./../package.json');

class NpmPackageJsonLint {

/**
* constructor
*/
Expand All @@ -28,7 +27,8 @@ class NpmPackageJsonLint {
const ruleModule = this.rules.get(rule);

if (ruleModule.ruleType === 'array' || ruleModule.ruleType === 'object') {
const severity = typeof configObj[rule] === 'string' && configObj[rule] === 'off' ? configObj[rule] : configObj[rule][0];
const severity =
typeof configObj[rule] === 'string' && configObj[rule] === 'off' ? configObj[rule] : configObj[rule][0];
const ruleConfig = configObj[rule][1];

if (severity !== 'off') {
Expand Down Expand Up @@ -72,7 +72,6 @@ class NpmPackageJsonLint {
getRule(rule) {
return this.rules.get(rule);
}

}

module.exports = NpmPackageJsonLint;
6 changes: 2 additions & 4 deletions src/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const stripComments = require('strip-json-comments');
* @return {Object} Config object from file.
* @throws {Error} If the file cannot be read.
*/
const requireFile = (fileName) => require(fileName);
const requireFile = fileName => require(fileName);

/**
* Sychronously reads file from file system
Expand All @@ -19,7 +19,7 @@ const requireFile = (fileName) => require(fileName);
* @return {String} File contents with BOM removed.
* @throws {Error} If the file cannot be read.
*/
const readFile = (fileName) => fs.readFileSync(fileName, 'utf8').replace(/^\ufeff/, '');
const readFile = fileName => fs.readFileSync(fileName, 'utf8').replace(/^\ufeff/, '');

/**
* Helper method for throwing errors when file fails to load.
Expand All @@ -38,7 +38,6 @@ const handleError = (fileName, err) => {
* @class
*/
class Parser {

/**
* Parse a JSON file
*
Expand Down Expand Up @@ -78,7 +77,6 @@ class Parser {

return obj;
}

}

module.exports = Parser;
5 changes: 1 addition & 4 deletions src/Reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const oneFile = 1;
* @returns {Undefined} No return
* @private
*/
const printResultSetIssues = (issues) => {
const printResultSetIssues = issues => {
for (const issue of issues) {
console.log(issue.toString());
}
Expand Down Expand Up @@ -49,7 +49,6 @@ const printIndividualResultSet = (resultSet, quiet) => {
console.log(chalk.yellow.bold(warningCountMessage));
}
}

};

/**
Expand Down Expand Up @@ -82,7 +81,6 @@ const printTotals = (cliEngineOutput, quiet) => {
* @class
*/
class Reporter {

/**
* Print CLIEngine Output
*
Expand All @@ -100,7 +98,6 @@ class Reporter {
printTotals(cliEngineOutput, quiet);
}
}

}

module.exports = Reporter;
4 changes: 1 addition & 3 deletions src/Rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const fs = require('fs');
const path = require('path');

class Rules {

/**
* Constructor
*/
Expand All @@ -21,7 +20,7 @@ class Rules {
const rulesDirectory = path.join(__dirname, 'rules');

try {
fs.readdirSync(rulesDirectory).forEach((file) => {
fs.readdirSync(rulesDirectory).forEach(file => {
const beginIndex = 0;
const endIndex = -3;
const ruleId = file.slice(beginIndex, endIndex);
Expand Down Expand Up @@ -71,7 +70,6 @@ class Rules {
_registerRule(ruleId, ruleModule) {
this.rules[ruleId] = ruleModule;
}

}

module.exports = Rules;
Loading

0 comments on commit 6d2b71a

Please sign in to comment.