Repository: tclindner/npm-package-json-lint (ts)

Issue:
Allow specifying values for private
We have a monorepo for our engineering team. We have a setup inspired by `babel`, `react` and others, where lots of npm packages live in a single repo. For all of those, we need to ensure that `private` is always set to true in the `package.json`. Is this something this tool could do?

Pull request description:
Add new valid-values-license rule
Closes #19

New rule: valid-values-license

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 799e2da..d82c241 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
 
 ### Removed
 
+## [1.4.0] - 2016-10-15
+### Added
+- New rule: [valid-values-license](https://github.com/tclindner/npm-package-json-lint/wiki/valid-values-license)
+
 ## [1.3.0] - 2016-07-26
 ### Added
 - New rule: [prefer-no-engineStrict](https://github.com/tclindner/npm-package-json-lint/wiki/prefer-no-engineStrict)
diff --git a/package.json b/package.json
index cbf45b8..17ac101 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "npm-package-json-lint",
-  "version": "1.3.0",
+  "version": "1.4.0",
   "description": "CLI app for linting package.json files.",
   "keywords": [
     "lint",
diff --git a/src/rules/valid-values-license.js b/src/rules/valid-values-license.js
new file mode 100644
index 0000000..822f8d4
--- /dev/null
+++ b/src/rules/valid-values-license.js
@@ -0,0 +1,27 @@
+'use strict';
+
+const LintIssue = require('./../LintIssue');
+const isValidValue = require('./../validators/valid-values').isValidValue;
+const lintId = 'valid-values-license';
+const nodeName = 'license';
+const message = 'Invalid value for license';
+const ruleType = 'valid-values';
+
+/**
+ * Lints package.json file to check for valid values in the license field
+ *
+ * @param  {Object}   packageJsonData   Valid package.json object
+ * @param  {String}   lintType          'error' or 'warning'
+ * @param  {Array}    validValues       An array of valid values
+ * @return {Object|Boolean}             LintIssue object if invalid. True if valid
+ */
+const lint = function(packageJsonData, lintType, validValues) {
+  if (!isValidValue(packageJsonData, nodeName, validValues)) {
+    return new LintIssue(lintId, lintType, nodeName, message);
+  }
+
+  return true;
+};
+
+module.exports.lint = lint;
+module.exports.ruleType = ruleType;


Test patch:
diff --git a/tests/unit/rules/valid-values-licenseTest.js b/tests/unit/rules/valid-values-licenseTest.js
new file mode 100644
index 0000000..26922a8
--- /dev/null
+++ b/tests/unit/rules/valid-values-licenseTest.js
@@ -0,0 +1,49 @@
+'use strict';
+
+const should = require('should');
+const requireHelper = require('../../require_helper');
+const lint = requireHelper('rules/valid-values-license').lint;
+
+describe('valid-values-license Unit Tests', function() {
+  context('when package.json has node with incorrect value', function() {
+    it('LintIssue object should be returned', function() {
+      const packageJsonData = {
+        license: 'MIT'
+      };
+      const validValues = [
+        'private',
+        'unlicensed'
+      ];
+      const response = lint(packageJsonData, 'error', validValues);
+
+      response.lintId.should.equal('valid-values-license');
+      response.lintType.should.equal('error');
+      response.node.should.equal('license');
+      response.lintMessage.should.equal('Invalid value for license');
+    });
+  });
+
+  context('when package.json has node with correct value', function() {
+    it('LintIssue object should be returned', function() {
+      const packageJsonData = {
+        license: 'unlicensed'
+      };
+      const validValues = [
+        'private',
+        'unlicensed'
+      ];
+      const response = lint(packageJsonData, 'error', validValues);
+
+      response.should.be.true();
+    });
+  });
+
+  context('when package.json does not have node', function() {
+    it('true should be returned', function() {
+      const packageJsonData = {};
+      const response = lint(packageJsonData, 'error');
+
+      response.should.be.true();
+    });
+  });
+});