From c32953c338e9e29e7ac8098e0876b6bf1d1b4cea Mon Sep 17 00:00:00 2001 From: Ben Rothman Date: Sun, 15 Nov 2015 13:07:28 -0600 Subject: [PATCH] Handle RegExp correctly in NameFormat conversion --- tests/rules.js | 112 ++++++++++++++++++++++++++++++++++++++++++++++++ translations.js | 8 ++-- 2 files changed, 115 insertions(+), 5 deletions(-) diff --git a/tests/rules.js b/tests/rules.js index cf65be7..e718dac 100644 --- a/tests/rules.js +++ b/tests/rules.js @@ -730,6 +730,34 @@ describe('Rule Conversion', function () { } ); + assert.deepStrictEqual( + scss2sass.convert({ + linters: { + 'NameFormat': { enabled: true, convention: 'camel_case' } + } + }).rules, + { + 'function-name-format': [1, { convention: 'camelcase' }], + 'mixin-name-format': [1, { convention: 'camelcase' }], + 'variable-name-format': [1, { convention: 'camelcase' }], + 'placeholder-name-format': [1, { convention: 'camelcase' }] + } + ); + + assert.deepStrictEqual( + scss2sass.convert({ + linters: { + 'NameFormat': { enabled: true, convention: 'foo' } + } + }).rules, + { + 'function-name-format': [1, { convention: 'foo' }], + 'mixin-name-format': [1, { convention: 'foo' }], + 'variable-name-format': [1, { convention: 'foo' }], + 'placeholder-name-format': [1, { convention: 'foo' }] + } + ); + assert.deepStrictEqual( scss2sass.convert({ linters: { @@ -758,6 +786,62 @@ describe('Rule Conversion', function () { } ); + assert.deepStrictEqual( + scss2sass.convert({ + linters: { + 'NameFormat': { enabled: true, mixin_convention: 'snake_case' } + } + }).rules, + { + 'function-name-format': 1, + 'mixin-name-format': [1, { convention: 'snakecase' }], + 'variable-name-format': 1, + 'placeholder-name-format': 1 + } + ); + + assert.deepStrictEqual( + scss2sass.convert({ + linters: { + 'NameFormat': { enabled: true, variable_convention: 'snake_case' } + } + }).rules, + { + 'function-name-format': 1, + 'mixin-name-format': 1, + 'variable-name-format': [1, { convention: 'snakecase' }], + 'placeholder-name-format': 1 + } + ); + + assert.deepStrictEqual( + scss2sass.convert({ + linters: { + 'NameFormat': { enabled: true, placeholder_convention: 'snake_case' } + } + }).rules, + { + 'function-name-format': 1, + 'mixin-name-format': 1, + 'variable-name-format': 1, + 'placeholder-name-format': [1, { convention: 'snakecase' }] + } + ); + + assert.deepStrictEqual( + scss2sass.convert({ + linters: { + 'NameFormat': { enabled: true, function_convention_explanation: 'foo' } + } + }).rules, + { + 'function-name-format': [1, { 'convention-explanation': 'foo' }], + 'mixin-name-format': 1, + 'variable-name-format': 1, + 'placeholder-name-format': 1 + } + ); + assert.deepStrictEqual( scss2sass.convert({ linters: { @@ -771,6 +855,34 @@ describe('Rule Conversion', function () { 'placeholder-name-format': 1 } ); + + assert.deepStrictEqual( + scss2sass.convert({ + linters: { + 'NameFormat': { enabled: true, variable_convention_explanation: 'foo' } + } + }).rules, + { + 'function-name-format': 1, + 'mixin-name-format': 1, + 'variable-name-format': [1, { 'convention-explanation': 'foo' }], + 'placeholder-name-format': 1 + } + ); + + assert.deepStrictEqual( + scss2sass.convert({ + linters: { + 'NameFormat': { enabled: true, placeholder_convention_explanation: 'foo' } + } + }).rules, + { + 'function-name-format': 1, + 'mixin-name-format': 1, + 'variable-name-format': 1, + 'placeholder-name-format': [1, { 'convention-explanation': 'foo' }] + } + ); }); it('NestingDepth', function () { diff --git a/translations.js b/translations.js index 15adf51..1c8c475 100644 --- a/translations.js +++ b/translations.js @@ -150,10 +150,7 @@ module.exports.NameFormat = { generalSettings = {}, types = ['function', 'mixin', 'placeholder', 'variable'], translateConvention = function (_convention) { - if (_convention instanceof RegExp) { - return _convention; - } - else if (_convention === 'hyphenated_lowercase') { + if (_convention === 'hyphenated_lowercase') { return 'hyphenatedlowercase'; } else if (_convention === 'snake_case') { @@ -163,7 +160,8 @@ module.exports.NameFormat = { return 'camelcase'; } else { - return 'ERROR_INVALID_CONVENTION'; + // default assumes a regexp + return _convention; } };