From dd60479d9a5dbc707476259b03f27c719f17e17d Mon Sep 17 00:00:00 2001 From: Augustinas <87965398+AugustinasVainius@users.noreply.github.com> Date: Wed, 19 Apr 2023 00:28:29 +0300 Subject: [PATCH] fix(formats): added missing EOL before EOF for some formats (#963) --- .../customFileHeader.test.js.snap | 9 ++-- .../__snapshots__/flutter.test.js.snap | 9 ++-- .../__snapshots__/objectValues.test.js.snap | 6 ++- .../__snapshots__/scss.test.js.snap | 12 +++-- .../formats/__snapshots__/all.test.js.snap | 45 ++++++++++++------- .../typeScriptEs6Declarations.test.js.snap | 3 +- lib/common/formats.js | 44 +++++++++++------- .../templates/flutter/class.dart.template | 2 +- 8 files changed, 85 insertions(+), 45 deletions(-) diff --git a/__integration__/__snapshots__/customFileHeader.test.js.snap b/__integration__/__snapshots__/customFileHeader.test.js.snap index 21ad10834..4108afcab 100644 --- a/__integration__/__snapshots__/customFileHeader.test.js.snap +++ b/__integration__/__snapshots__/customFileHeader.test.js.snap @@ -60,7 +60,8 @@ module.exports = { ] } } -};" +}; +" `; exports[`integration valid custom file headers platform options no file options should match snapshot 1`] = ` @@ -88,7 +89,8 @@ module.exports = { ] } } -};" +}; +" `; exports[`integration valid custom file headers platform options showFileHeader should match snapshot 1`] = ` @@ -110,5 +112,6 @@ exports[`integration valid custom file headers platform options showFileHeader s ] } } -};" +}; +" `; diff --git a/__integration__/__snapshots__/flutter.test.js.snap b/__integration__/__snapshots__/flutter.test.js.snap index bad987aaf..fdb6fbc35 100644 --- a/__integration__/__snapshots__/flutter.test.js.snap +++ b/__integration__/__snapshots__/flutter.test.js.snap @@ -169,7 +169,8 @@ class StyleDictionaryColor { static const fontSuccess = Color(0xFF08422F); static const fontTertiary = Color(0xFF364141); static const fontWarning = Color(0xFF601700); -}" +} +" `; exports[`integration flutter flutter/class.dart should match snapshot 1`] = ` @@ -350,7 +351,8 @@ class StyleDictionary { static const sizePaddingMedium = 16.00; static const sizePaddingSmall = 8.00; static const sizePaddingXl = 16.00; -}" +} +" `; exports[`integration flutter flutter/class.dart with references should match snapshot 1`] = ` @@ -531,5 +533,6 @@ class StyleDictionary { static const colorFontInteractiveHover = colorBrandPrimary; static const colorFontInteractive = colorBrandPrimary; static const colorBackgroundDisabled = colorBackgroundTertiary; -}" +} +" `; diff --git a/__integration__/__snapshots__/objectValues.test.js.snap b/__integration__/__snapshots__/objectValues.test.js.snap index 4364e38f0..63e155095 100644 --- a/__integration__/__snapshots__/objectValues.test.js.snap +++ b/__integration__/__snapshots__/objectValues.test.js.snap @@ -107,7 +107,8 @@ exports[`integration object values scss/variables should match snapshot 1`] = ` // Do not edit directly // Generated on Sat, 01 Jan 2000 00:00:00 GMT -$border-primary: 0.125rem solid #ff0000;" +$border-primary: 0.125rem solid #ff0000; +" `; exports[`integration object values scss/variables with references should match snapshot 1`] = ` @@ -115,5 +116,6 @@ exports[`integration object values scss/variables with references should match s // Do not edit directly // Generated on Sat, 01 Jan 2000 00:00:00 GMT -$border-primary: $size-border solid $color-red;" +$border-primary: $size-border solid $color-red; +" `; diff --git a/__integration__/__snapshots__/scss.test.js.snap b/__integration__/__snapshots__/scss.test.js.snap index a36409dea..2fab321f8 100644 --- a/__integration__/__snapshots__/scss.test.js.snap +++ b/__integration__/__snapshots__/scss.test.js.snap @@ -1507,7 +1507,8 @@ $size-font-xl: 2.25rem; $size-padding-small: 0.5rem; $size-padding-medium: 1rem; $size-padding-large: 1rem; -$size-padding-xl: 1rem;" +$size-padding-xl: 1rem; +" `; exports[`integration scss scss/variables with filter and output references should match snapshot 1`] = ` @@ -1522,7 +1523,8 @@ $color-background-danger: $color-core-red-0; $color-background-tertiary: $color-core-neutral-200; $color-background-secondary: $color-core-neutral-100; $color-background-primary: $color-core-neutral-0 !default; -$color-background-disabled: $color-background-tertiary;" +$color-background-disabled: $color-background-tertiary; +" `; exports[`integration scss scss/variables with outputReferences should match snapshot 1`] = ` @@ -1691,7 +1693,8 @@ $color-font-interactive-disabled: $color-font-tertiary; $color-font-interactive-active: $color-brand-secondary; $color-font-interactive-hover: $color-brand-primary; $color-font-interactive: $color-brand-primary; -$color-background-disabled: $color-background-tertiary;" +$color-background-disabled: $color-background-tertiary; +" `; exports[`integration scss scss/variables with themeable should match snapshot 1`] = ` @@ -1860,5 +1863,6 @@ $size-font-xl: 2.25rem !default; $size-padding-small: 0.5rem !default; $size-padding-medium: 1rem !default; $size-padding-large: 1rem !default; -$size-padding-xl: 1rem !default;" +$size-padding-xl: 1rem !default; +" `; diff --git a/__tests__/formats/__snapshots__/all.test.js.snap b/__tests__/formats/__snapshots__/all.test.js.snap index f514a9bd6..8c209b615 100644 --- a/__tests__/formats/__snapshots__/all.test.js.snap +++ b/__tests__/formats/__snapshots__/all.test.js.snap @@ -134,7 +134,8 @@ class { ._(); static const color_red = #FF0000; /* comment */ -}" +} +" `; exports[`formats all should match ios/colors.h snapshot 1`] = ` @@ -466,7 +467,8 @@ exports[`formats all should match javascript/es6 snapshot 1`] = ` * Generated on Sat, 01 Jan 2000 00:00:00 GMT */ -export const color_red = \\"#FF0000\\"; // comment" +export const color_red = \\"#FF0000\\"; // comment +" `; exports[`formats all should match javascript/module snapshot 1`] = ` @@ -494,7 +496,8 @@ module.exports = { ] } } -};" +}; +" `; exports[`formats all should match javascript/module-flat snapshot 1`] = ` @@ -505,7 +508,8 @@ exports[`formats all should match javascript/module-flat snapshot 1`] = ` module.exports = { \\"color_red\\": \\"#FF0000\\" -};" +}; +" `; exports[`formats all should match javascript/object snapshot 1`] = ` @@ -533,7 +537,8 @@ var _styleDictionary = { ] } } -};" +}; +" `; exports[`formats all should match javascript/umd snapshot 1`] = ` @@ -597,7 +602,8 @@ exports[`formats all should match json snapshot 1`] = ` ] } } -}" +} +" `; exports[`formats all should match json/asset snapshot 1`] = `"{}"`; @@ -605,7 +611,8 @@ exports[`formats all should match json/asset snapshot 1`] = `"{}"`; exports[`formats all should match json/flat snapshot 1`] = ` "{ \\"color_red\\": \\"#FF0000\\" -}" +} +" `; exports[`formats all should match json/nested snapshot 1`] = ` @@ -613,7 +620,8 @@ exports[`formats all should match json/nested snapshot 1`] = ` \\"color\\": { \\"red\\": \\"#FF0000\\" } -}" +} +" `; exports[`formats all should match less/icons snapshot 1`] = ` @@ -629,7 +637,8 @@ exports[`formats all should match less/variables snapshot 1`] = ` // Do not edit directly // Generated on Sat, 01 Jan 2000 00:00:00 GMT -@color_red: #FF0000; // comment" +@color_red: #FF0000; // comment +" `; exports[`formats all should match sass/map-deep snapshot 1`] = ` @@ -707,7 +716,8 @@ exports[`formats all should match scss/variables snapshot 1`] = ` // Do not edit directly // Generated on Sat, 01 Jan 2000 00:00:00 GMT -$color_red: #FF0000; // comment" +$color_red: #FF0000; // comment +" `; exports[`formats all should match sketch/palette snapshot 1`] = ` @@ -715,7 +725,8 @@ exports[`formats all should match sketch/palette snapshot 1`] = ` \\"compatibleVersion\\": \\"1.0\\", \\"pluginVersion\\": \\"1.1\\", \\"colors\\": [] -}" +} +" `; exports[`formats all should match sketch/palette/v2 snapshot 1`] = ` @@ -734,7 +745,8 @@ exports[`formats all should match sketch/palette/v2 snapshot 1`] = ` \\"name\\": \\"color_red\\" } ] -}" +} +" `; exports[`formats all should match stylus/variables snapshot 1`] = ` @@ -742,7 +754,8 @@ exports[`formats all should match stylus/variables snapshot 1`] = ` // Do not edit directly // Generated on Sat, 01 Jan 2000 00:00:00 GMT -$color_red= #FF0000; // comment" +$color_red= #FF0000; // comment +" `; exports[`formats all should match typescript/es6-declarations snapshot 1`] = ` @@ -752,7 +765,8 @@ exports[`formats all should match typescript/es6-declarations snapshot 1`] = ` */ /** comment */ -export const color_red : string;" +export const color_red : string; +" `; exports[`formats all should match typescript/module-declarations snapshot 1`] = ` @@ -783,5 +797,6 @@ declare const tokens: { \\"color\\": { \\"red\\": DesignToken } -}" +} +" `; diff --git a/__tests__/formats/__snapshots__/typeScriptEs6Declarations.test.js.snap b/__tests__/formats/__snapshots__/typeScriptEs6Declarations.test.js.snap index 9343df8be..8d567211b 100644 --- a/__tests__/formats/__snapshots__/typeScriptEs6Declarations.test.js.snap +++ b/__tests__/formats/__snapshots__/typeScriptEs6Declarations.test.js.snap @@ -7,5 +7,6 @@ exports[`formats typescript/es6-declarations with outputStringLiterals should ma */ /** Used for errors */ -export const colorRed : \\"#FF0000\\";" +export const colorRed : \\"#FF0000\\"; +" `; diff --git a/lib/common/formats.js b/lib/common/formats.js index adcae9547..f7f8caa7c 100644 --- a/lib/common/formats.js +++ b/lib/common/formats.js @@ -15,7 +15,18 @@ const fs = require('fs'); const path = require('path'); const _template = require('lodash/template'); const GroupMessages = require('../utils/groupMessages'); -const { fileHeader, formattedVariables, getTypeScriptType, iconsWithPrefix, minifyDictionary, sortByReference, createPropertyFormatter, sortByName, setSwiftFileProperties, setComposeObjectProperties } = require('./formatHelpers'); +const { + fileHeader, + formattedVariables, + getTypeScriptType, + iconsWithPrefix, + minifyDictionary, + sortByReference, + createPropertyFormatter, + sortByName, + setSwiftFileProperties, + setComposeObjectProperties +} = require('./formatHelpers'); const SASS_MAP_FORMAT_DEPRECATION_WARNINGS = GroupMessages.GROUP.SassMapFormatDeprecationWarnings; @@ -140,7 +151,7 @@ module.exports = { 'scss/variables': function({dictionary, options, file}) { const { outputReferences, themeable = false } = options; return fileHeader({file, commentStyle: 'short'}) + - formattedVariables({format: 'sass', dictionary, outputReferences, themeable}); + formattedVariables({format: 'sass', dictionary, outputReferences, themeable}) + '\n'; }, /** @@ -175,7 +186,7 @@ module.exports = { 'less/variables': function({dictionary, options, file}) { const { outputReferences } = options; return fileHeader({file, commentStyle: 'short'}) + - formattedVariables({format: 'less', dictionary, outputReferences}); + formattedVariables({format: 'less', dictionary, outputReferences}) + '\n'; }, /** @@ -207,7 +218,7 @@ module.exports = { 'stylus/variables': function({dictionary, options, file}) { const { outputReferences } = options; return fileHeader({file, commentStyle: 'short'}) + - formattedVariables({format: 'stylus', dictionary, outputReferences}); + formattedVariables({format: 'stylus', dictionary, outputReferences}) + '\n'; }, /** @@ -231,7 +242,7 @@ module.exports = { 'javascript/module': function({dictionary, file}) { return fileHeader({file}) + 'module.exports = ' + - JSON.stringify(dictionary.tokens, null, 2) + ';'; + JSON.stringify(dictionary.tokens, null, 2) + ';\n'; }, /** @@ -248,8 +259,9 @@ module.exports = { */ 'javascript/module-flat': function({dictionary, file}) { return fileHeader({file}) + - 'module.exports = ' + - module.exports['json/flat']({dictionary}) + ';'; + 'module.exports = ' + '{\n' + dictionary.allTokens.map(function(token) { + return ` "${token.name}": ${JSON.stringify(token.value)}`; + }).join(',\n') + '\n}' + ';\n'; }, /** @@ -277,7 +289,7 @@ module.exports = { (file.name || '_styleDictionary') + ' = ' + JSON.stringify(dictionary.tokens, null, 2) + - ';'; + ';\n'; }, /** @@ -367,7 +379,7 @@ module.exports = { if (token.comment) to_ret = to_ret.concat(' // ' + token.comment); return to_ret; - }).join('\n'); + }).join('\n') + '\n'; }, // TypeScript declarations @@ -412,7 +424,7 @@ module.exports = { to_ret_prop += '/** ' + prop.comment + ' */\n'; to_ret_prop += 'export const ' + prop.name + ' : ' + getTypeScriptType(prop.value, options) + ';'; return to_ret_prop; - }).join('\n'); + }).join('\n') + '\n'; }, /** @@ -505,7 +517,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul // JSON stringify will quote strings, because this is a type we need // it unquoted. - return output.replace(/"DesignToken"/g,'DesignToken'); + return output.replace(/"DesignToken"/g, 'DesignToken') + '\n'; }, // Android templates @@ -1075,7 +1087,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul * ``` */ 'json': function({dictionary}) { - return JSON.stringify(dictionary.tokens, null, 2); + return JSON.stringify(dictionary.tokens, null, 2) + '\n'; }, /** @@ -1117,7 +1129,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul * ``` */ 'json/nested': function({dictionary}) { - return JSON.stringify(minifyDictionary(dictionary.tokens), null, 2); + return JSON.stringify(minifyDictionary(dictionary.tokens), null, 2) + '\n'; }, /** @@ -1135,7 +1147,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul 'json/flat': function({dictionary}) { return '{\n' + dictionary.allTokens.map(function(token) { return ` "${token.name}": ${JSON.stringify(token.value)}`; - }).join(',\n') + '\n}'; + }).join(',\n') + '\n}' + '\n'; }, /** @@ -1168,7 +1180,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul .map(function(token) { return token.value; }); - return JSON.stringify(to_ret, null, 2); + return JSON.stringify(to_ret, null, 2) + '\n'; }, /** @@ -1202,7 +1214,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul }, token.value) }) }; - return JSON.stringify(to_ret, null, 2); + return JSON.stringify(to_ret, null, 2) + '\n'; }, diff --git a/lib/common/templates/flutter/class.dart.template b/lib/common/templates/flutter/class.dart.template index bf648bd59..482d9ff61 100644 --- a/lib/common/templates/flutter/class.dart.template +++ b/lib/common/templates/flutter/class.dart.template @@ -23,4 +23,4 @@ class <%= file.className %> { <%= allTokens.map(function(prop) { return 'static const ' + formatProperty(prop); }).join('\n ') %> -} \ No newline at end of file +}