Repository: brenolf/polyjuice (js)

Issue:
Add `SpacesInGenerator` rules
* http://jscs.info/rule/disallowSpacesInGenerator
* http://jscs.info/rule/requireSpacesInGenerator

Pull request description:
Resolves #39

Patch:
diff --git a/lib/dictionaries/jscs/validateCommentPosition.js b/lib/dictionaries/jscs/disallowSpacesInGenerator.js
similarity index 53%
rename from lib/dictionaries/jscs/validateCommentPosition.js
rename to lib/dictionaries/jscs/disallowSpacesInGenerator.js
index a0cf868..5fb3b17 100644
--- a/lib/dictionaries/jscs/validateCommentPosition.js
+++ b/lib/dictionaries/jscs/disallowSpacesInGenerator.js
@@ -1,5 +1,5 @@
 /**
-* @fileoverview Translation for `validateCommentPosition` (JSCS) to ESLint
+* @fileoverview Translation for `disallowSpacesInGenerator` (JSCS) to ESLint
 * @author Breno Lima de Freitas <https://breno.io>
 * @copyright 2016 Breno Lima de Freitas. All rights reserved.
 * See LICENSE file in root directory for full license.
@@ -11,12 +11,19 @@
 // Rule Translation Definition
 //------------------------------------------------------------------------------
 
-module.exports = function(__current__, value) {
-  if (value.position === 'beside') {
-    return {
-      'no-inline-comments': 2
+module.exports = {
+  name: 'generator-star-spacing',
+  truthy: function(__current__, value) {
+    var obj = __current__ ? __current__[1] : {}
+
+    if (value.beforeStar) {
+      obj.before = false
     }
-  }
 
-  return {}
+    if (value.afterStar) {
+      obj.after = false
+    }
+
+    return [2, obj]
+  }
 };
diff --git a/lib/dictionaries/jscs/disallowUnusedParams.js b/lib/dictionaries/jscs/disallowUnusedParams.js
index ae97904..35c0f42 100644
--- a/lib/dictionaries/jscs/disallowUnusedParams.js
+++ b/lib/dictionaries/jscs/disallowUnusedParams.js
@@ -11,18 +11,4 @@
 // Rule Translation Definition
 //------------------------------------------------------------------------------
 
-module.exports = {
-  name: 'no-unused-vars',
-  truthy: function(__current__) {
-    if (__current__) {
-      __current__[1].args = 'all'
-
-      return __current__
-    }
-
-    return [2, {
-      vars: 'local',
-      args: 'all'
-    }]
-  }
-}
+module.exports = 'no-unused-vars';
diff --git a/lib/dictionaries/jscs/disallowUnusedVariables.js b/lib/dictionaries/jscs/requireSpacesInGenerator.js
similarity index 55%
rename from lib/dictionaries/jscs/disallowUnusedVariables.js
rename to lib/dictionaries/jscs/requireSpacesInGenerator.js
index 8a75381..78a63e0 100644
--- a/lib/dictionaries/jscs/disallowUnusedVariables.js
+++ b/lib/dictionaries/jscs/requireSpacesInGenerator.js
@@ -1,5 +1,5 @@
 /**
-* @fileoverview Translation for `disallowUnusedVariables` (JSCS) to ESLint
+* @fileoverview Translation for `requireSpacesInGenerator` (JSCS) to ESLint
 * @author Breno Lima de Freitas <https://breno.io>
 * @copyright 2016 Breno Lima de Freitas. All rights reserved.
 * See LICENSE file in root directory for full license.
@@ -12,17 +12,18 @@
 //------------------------------------------------------------------------------
 
 module.exports = {
-  name: 'no-unused-vars',
-  truthy: function(__current__) {
-    if (__current__) {
-      __current__[1].vars = 'all'
+  name: 'generator-star-spacing',
+  truthy: function(__current__, value) {
+    var obj = __current__ ? __current__[1] : {}
 
-      return __current__
+    if (value.beforeStar) {
+      obj.before = true
     }
 
-    return [2, {
-      vars: 'all',
-      args: 'none'
-    }]
+    if (value.afterStar) {
+      obj.after = true
+    }
+
+    return [2, obj]
   }
-}
+};


Test patch:
diff --git a/test/dictionaries/jscs/disallowSpacesInGenerator.test.js b/test/dictionaries/jscs/disallowSpacesInGenerator.test.js
new file mode 100644
index 0000000..5c3b7db
--- /dev/null
+++ b/test/dictionaries/jscs/disallowSpacesInGenerator.test.js
@@ -0,0 +1,52 @@
+/**
+ * @fileoverview Tests for `disallowSpacesInGenerator` (JSCS) translation
+ * @author Breno Lima de Freitas <https://breno.io>
+ * @copyright 2016 Breno Lima de Freitas. All rights reserved.
+ * See LICENSE file in root directory for full license.
+ */
+
+'use strict'
+
+//------------------------------------------------------------------------------
+// Requirements
+//------------------------------------------------------------------------------
+
+var lib = require('../../../lib/dictionaries/jscs/disallowSpacesInGenerator.js')
+
+var getFn = caller(lib)
+
+describe('jscs#disallowSpacesInGenerator', function() {
+  it('converts the rule correctly', function() {
+    var fn = getFn()
+    var fnBound = getFn([2, {
+      before: true
+    }])
+
+    expect(fn({
+      beforeStar: false,
+      afterStar: true
+    })).to.eql([2, {
+      after: false
+    }])
+
+    expect(fnBound({
+      beforeStar: true,
+      afterStar: true
+    })).to.eql([2, {
+      after: false,
+      before: false
+    }])
+
+    expect(fn({
+      beforeStar: true,
+      afterStar: false
+    })).to.eql([2, {
+      before: false
+    }])
+
+    expect(fn({
+      beforeStar: false,
+      afterStar: false
+    })).to.eql([2, {}])
+  })
+})
diff --git a/test/dictionaries/jscs/disallowUnusedParams.test.js b/test/dictionaries/jscs/disallowUnusedParams.test.js
deleted file mode 100644
index b2c33b1..0000000
--- a/test/dictionaries/jscs/disallowUnusedParams.test.js
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * @fileoverview Tests for `disallowUnusedParams` (JSCS) translation
- * @author Breno Lima de Freitas <https://breno.io>
- * @copyright 2016 Breno Lima de Freitas. All rights reserved.
- * See LICENSE file in root directory for full license.
- */
-
-'use strict'
-
-//------------------------------------------------------------------------------
-// Requirements
-//------------------------------------------------------------------------------
-
-var lib = require('../../../lib/dictionaries/jscs/disallowUnusedParams.js')
-
-var getFn = caller(lib)
-
-describe('jscs#disallowUnusedParams', function() {
-  it('converts the rule correctly', function() {
-    var fn = getFn()
-
-    var fnBound = getFn([2, {
-      vars: 'xxx',
-      args: 'none'
-    }])
-
-    expect(fn()).to.eql([2, {
-      vars: 'local',
-      args: 'all'
-    }])
-
-    expect(fnBound()).to.eql([2, {
-      vars: 'xxx',
-      args: 'all'
-    }])
-  })
-})
diff --git a/test/dictionaries/jscs/disallowUnusedVariables.test.js b/test/dictionaries/jscs/disallowUnusedVariables.test.js
deleted file mode 100644
index 30f061d..0000000
--- a/test/dictionaries/jscs/disallowUnusedVariables.test.js
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * @fileoverview Tests for `disallowUnusedVariables` (JSCS) translation
- * @author Breno Lima de Freitas <https://breno.io>
- * @copyright 2016 Breno Lima de Freitas. All rights reserved.
- * See LICENSE file in root directory for full license.
- */
-
-'use strict'
-
-//------------------------------------------------------------------------------
-// Requirements
-//------------------------------------------------------------------------------
-
-var lib = require('../../../lib/dictionaries/jscs/disallowUnusedVariables.js')
-
-var getFn = caller(lib)
-
-describe('jscs#disallowUnusedVariables', function() {
-  it('converts the rule correctly', function() {
-    var fn = getFn()
-
-    var fnBound = getFn([2, {
-      vars: 'local',
-      args: 'xxx'
-    }])
-
-    expect(fn()).to.eql([2, {
-      vars: 'all',
-      args: 'none'
-    }])
-
-    expect(fnBound()).to.eql([2, {
-      vars: 'all',
-      args: 'xxx'
-    }])
-  })
-})
diff --git a/test/dictionaries/jscs/requireSpacesInGenerator.test.js b/test/dictionaries/jscs/requireSpacesInGenerator.test.js
new file mode 100644
index 0000000..426a7dd
--- /dev/null
+++ b/test/dictionaries/jscs/requireSpacesInGenerator.test.js
@@ -0,0 +1,52 @@
+/**
+ * @fileoverview Tests for `requireSpacesInGenerator` (JSCS) translation
+ * @author Breno Lima de Freitas <https://breno.io>
+ * @copyright 2016 Breno Lima de Freitas. All rights reserved.
+ * See LICENSE file in root directory for full license.
+ */
+
+'use strict'
+
+//------------------------------------------------------------------------------
+// Requirements
+//------------------------------------------------------------------------------
+
+var lib = require('../../../lib/dictionaries/jscs/requireSpacesInGenerator.js')
+
+var getFn = caller(lib)
+
+describe('jscs#requireSpacesInGenerator', function() {
+  it('converts the rule correctly', function() {
+    var fn = getFn()
+    var fnBound = getFn([2, {
+      before: true
+    }])
+
+    expect(fn({
+      beforeStar: false,
+      afterStar: true
+    })).to.eql([2, {
+      after: true
+    }])
+
+    expect(fnBound({
+      beforeStar: false,
+      afterStar: true
+    })).to.eql([2, {
+      after: true,
+      before: true
+    }])
+
+    expect(fn({
+      beforeStar: true,
+      afterStar: false
+    })).to.eql([2, {
+      before: true
+    }])
+
+    expect(fn({
+      beforeStar: false,
+      afterStar: false
+    })).to.eql([2, {}])
+  })
+})
diff --git a/test/dictionaries/jscs/validateCommentPosition.test.js b/test/dictionaries/jscs/validateCommentPosition.test.js
deleted file mode 100644
index 0427b01..0000000
--- a/test/dictionaries/jscs/validateCommentPosition.test.js
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * @fileoverview Tests for `validateCommentPosition` (JSCS) translation
- * @author Breno Lima de Freitas <https://breno.io>
- * @copyright 2016 Breno Lima de Freitas. All rights reserved.
- * See LICENSE file in root directory for full license.
- */
-
-'use strict'
-
-//------------------------------------------------------------------------------
-// Requirements
-//------------------------------------------------------------------------------
-
-var lib = require('../../../lib/dictionaries/jscs/validateCommentPosition.js')
-
-var getFn = caller(lib)
-
-describe('jscs#validateCommentPosition', function() {
-  it('converts the rule correctly', function() {
-    var fn = getFn()
-
-    expect(fn({
-      position: 'above',
-      allExcept: ['pragma']
-    })).to.be.empty
-
-    expect(fn({
-      position: 'beside',
-      allExcept: ['pragma']
-    })).to.eql({
-      'no-inline-comments': 2
-    })
-  })
-})