Skip to content

Commit d7721e6

Browse files
authored
Merge pull request #19 from awssat/analysis-KZB5bQ
Apply fixes from StyleCI
2 parents a262fd4 + 04e1f86 commit d7721e6

File tree

4 files changed

+55
-56
lines changed

4 files changed

+55
-56
lines changed

src/ConfigFileFixer.php

+39-39
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function fixForVersion1_0()
6767
//1: get options{} values and add em to root of 'module.exports' and add last value as theme: {..
6868
preg_match('/options:\s*\{([^\}]+)\},?/', $this->searchAndReplace->get(), $match);
6969
$options = $match[1] ?? '';
70-
$updatedToThemeKey = "module.exports = {\n" . $options . "\n\ntheme: {\n";
70+
$updatedToThemeKey = "module.exports = {\n".$options."\n\ntheme: {\n";
7171

7272
$this->searchAndReplace->perform('options:\s*\{([^\}]+)\},?', '', SearchAndReplace::NO_ESCAPE);
7373
$this->searchAndReplace->perform('module.exports\s*=\s*\{', $updatedToThemeKey, SearchAndReplace::NO_ESCAPE);
@@ -95,12 +95,12 @@ protected function fixForVersion1_0()
9595
'lists\:{regex_line}' => "listStylePosition:{regex_line}\nlistStyleType:{regex_line}",
9696
'position\:{regex_line}' => "position:{regex_line}\ninset:{regex_line}",
9797
'whitespace\:{regex_line}' => "whitespace:{regex_line}\nwordBreak:{regex_line}",
98-
'textStyle\:{regex_line}' => "fontStyle:{regex_line}\nfontSmoothing:{regex_line}" .
98+
'textStyle\:{regex_line}' => "fontStyle:{regex_line}\nfontSmoothing:{regex_line}".
9999
"\ntextDecoration:{regex_line}\ntextTransform:{regex_line}",
100-
'flexbox\:{regex_line}' => "flexDirection:{regex_line}\nflexWrap:{regex_line}" .
101-
"\nalignItems:{regex_line}\nalignSelf:{regex_line}" .
102-
"\njustifyContent:{regex_line}\nalignContent:{regex_line}" .
103-
"\nflex:{regex_line}\nflexGrow:{regex_line}" .
100+
'flexbox\:{regex_line}' => "flexDirection:{regex_line}\nflexWrap:{regex_line}".
101+
"\nalignItems:{regex_line}\nalignSelf:{regex_line}".
102+
"\njustifyContent:{regex_line}\nalignContent:{regex_line}".
103+
"\nflex:{regex_line}\nflexGrow:{regex_line}".
104104
"\nflexShrink:{regex_line}",
105105
];
106106

@@ -114,46 +114,46 @@ protected function fixForVersion1_0()
114114
$containerOptions = $match[1] ?? '';
115115

116116
$this->searchAndReplace->perform('require\(\'tailwindcss\/plugins\/container\'\)\(\{([^\}]+)\}\),?', '', SearchAndReplace::NO_ESCAPE);
117-
$corePlugins = 'corePlugins: {' . (empty($containerOptions) ? "\ncontainer: false," : '') . "\n}, \nplugins: [";
117+
$corePlugins = 'corePlugins: {'.(empty($containerOptions) ? "\ncontainer: false," : '')."\n}, \nplugins: [";
118118

119119
$this->searchAndReplace->perform('plugins:\s*\[', $corePlugins, SearchAndReplace::NO_ESCAPE);
120-
$this->searchAndReplace->perform('theme:\s*\{', "theme: \n{\ncontainer: {\n" . $containerOptions . "\n},\n", SearchAndReplace::NO_ESCAPE);
120+
$this->searchAndReplace->perform('theme:\s*\{', "theme: \n{\ncontainer: {\n".$containerOptions."\n},\n", SearchAndReplace::NO_ESCAPE);
121121

122122
//8: fix colors
123-
$colors = "\n transparent: 'transparent',\n\n black: '#000',\n white: '#fff'," .
124-
"\n gray: {\n100: '#f7fafc',\n200: '#edf2f7',\n300: '#e2e8f0'," .
125-
"\n400: '#cbd5e0',\n500: '#a0aec0',\n600: '#718096',\n700: '#4a5568'," .
126-
"\n800: '#2d3748',\n900: '#1a202c',\n},\n" .
127-
"\n red: {\n100: '#fff5f5',\n200: '#fed7d7',\n300: '#feb2b2',\n400: '#fc8181'," .
128-
"\n500: '#f56565',\n600: '#e53e3e',\n700: '#c53030',\n800: '#9b2c2c'," .
129-
"\n900: '#742a2a',\n},\n" .
130-
"\n orange: {\n100: '#fffaf0',\n200: '#feebc8',\n300: '#fbd38d'," .
131-
"\n400: '#f6ad55',\n500: '#ed8936',\n600: '#dd6b20',\n700: '#c05621'," .
132-
"\n800: '#9c4221',\n900: '#7b341e',\n},\n" .
133-
"\n yellow: {\n100: '#fffff0',\n200: '#fefcbf',\n300: '#faf089'," .
134-
"\n400: '#f6e05e',\n500: '#ecc94b',\n600: '#d69e2e',\n700: '#b7791f'," .
135-
"\n800: '#975a16',\n900: '#744210',\n},\n" .
136-
"\n green: {\n100: '#f0fff4',\n200: '#c6f6d5',\n300: '#9ae6b4'," .
137-
"\n400: '#68d391',\n500: '#48bb78',\n600: '#38a169',\n700: '#2f855a'," .
138-
"\n800: '#276749',\n900: '#22543d',\n}," .
139-
"\n teal: {\n100: '#e6fffa',\n200: '#b2f5ea',\n300: '#81e6d9'," .
140-
"\n400: '#4fd1c5',\n500: '#38b2ac',\n600: '#319795',\n700: '#2c7a7b'," .
141-
"\n800: '#285e61',\n900: '#234e52',\n},\n" .
142-
"\n blue: {\n100: '#ebf8ff',\n200: '#bee3f8',\n300: '#90cdf4'," .
143-
"\n400: '#63b3ed',\n500: '#4299e1',\n600: '#3182ce',\n700: '#2b6cb0', " .
144-
"\n800: '#2c5282',\n900: '#2a4365',\n}," .
145-
"\n indigo: {\n100: '#ebf4ff',\n200: '#c3dafe',\n300: '#a3bffa'," .
146-
"\n400: '#7f9cf5',\n500: '#667eea',\n600: '#5a67d8',\n700: '#4c51bf'," .
147-
"\n800: '#434190',\n900: '#3c366b',\n},\n" .
148-
"\n purple: {\n100: '#faf5ff',\n200: '#e9d8fd',\n300: '#d6bcfa'," .
149-
"\n400: '#b794f4',\n500: '#9f7aea',\n600: '#805ad5',\n700: '#6b46c1'," .
150-
"\n800: '#553c9a',\n900: '#44337a',\n},\n" .
151-
"\n pink: {\n100: '#fff5f7',\n200: '#fed7e2',\n300: '#fbb6ce'," .
152-
"\n400: '#f687b3',\n500: '#ed64a6',\n600: '#d53f8c',\n700: '#b83280'," .
123+
$colors = "\n transparent: 'transparent',\n\n black: '#000',\n white: '#fff',".
124+
"\n gray: {\n100: '#f7fafc',\n200: '#edf2f7',\n300: '#e2e8f0',".
125+
"\n400: '#cbd5e0',\n500: '#a0aec0',\n600: '#718096',\n700: '#4a5568',".
126+
"\n800: '#2d3748',\n900: '#1a202c',\n},\n".
127+
"\n red: {\n100: '#fff5f5',\n200: '#fed7d7',\n300: '#feb2b2',\n400: '#fc8181',".
128+
"\n500: '#f56565',\n600: '#e53e3e',\n700: '#c53030',\n800: '#9b2c2c',".
129+
"\n900: '#742a2a',\n},\n".
130+
"\n orange: {\n100: '#fffaf0',\n200: '#feebc8',\n300: '#fbd38d',".
131+
"\n400: '#f6ad55',\n500: '#ed8936',\n600: '#dd6b20',\n700: '#c05621',".
132+
"\n800: '#9c4221',\n900: '#7b341e',\n},\n".
133+
"\n yellow: {\n100: '#fffff0',\n200: '#fefcbf',\n300: '#faf089',".
134+
"\n400: '#f6e05e',\n500: '#ecc94b',\n600: '#d69e2e',\n700: '#b7791f',".
135+
"\n800: '#975a16',\n900: '#744210',\n},\n".
136+
"\n green: {\n100: '#f0fff4',\n200: '#c6f6d5',\n300: '#9ae6b4',".
137+
"\n400: '#68d391',\n500: '#48bb78',\n600: '#38a169',\n700: '#2f855a',".
138+
"\n800: '#276749',\n900: '#22543d',\n},".
139+
"\n teal: {\n100: '#e6fffa',\n200: '#b2f5ea',\n300: '#81e6d9',".
140+
"\n400: '#4fd1c5',\n500: '#38b2ac',\n600: '#319795',\n700: '#2c7a7b',".
141+
"\n800: '#285e61',\n900: '#234e52',\n},\n".
142+
"\n blue: {\n100: '#ebf8ff',\n200: '#bee3f8',\n300: '#90cdf4',".
143+
"\n400: '#63b3ed',\n500: '#4299e1',\n600: '#3182ce',\n700: '#2b6cb0', ".
144+
"\n800: '#2c5282',\n900: '#2a4365',\n},".
145+
"\n indigo: {\n100: '#ebf4ff',\n200: '#c3dafe',\n300: '#a3bffa',".
146+
"\n400: '#7f9cf5',\n500: '#667eea',\n600: '#5a67d8',\n700: '#4c51bf',".
147+
"\n800: '#434190',\n900: '#3c366b',\n},\n".
148+
"\n purple: {\n100: '#faf5ff',\n200: '#e9d8fd',\n300: '#d6bcfa',".
149+
"\n400: '#b794f4',\n500: '#9f7aea',\n600: '#805ad5',\n700: '#6b46c1',".
150+
"\n800: '#553c9a',\n900: '#44337a',\n},\n".
151+
"\n pink: {\n100: '#fff5f7',\n200: '#fed7e2',\n300: '#fbb6ce',".
152+
"\n400: '#f687b3',\n500: '#ed64a6',\n600: '#d53f8c',\n700: '#b83280',".
153153
"\n800: '#97266d',\n900: '#702459',\n},\n";
154154

155155
$this->searchAndReplace->perform('let colors\s*=\s*\{([^\}]+)\}', '', SearchAndReplace::NO_ESCAPE);
156-
$this->searchAndReplace->perform('\s+colors:\s*colors', ' colors: {' . $colors . '}', SearchAndReplace::NO_ESCAPE);
156+
$this->searchAndReplace->perform('\s+colors:\s*colors', ' colors: {'.$colors.'}', SearchAndReplace::NO_ESCAPE);
157157
$this->searchAndReplace->perform('backgroundColor:\s*colors', 'backgroundColor: theme => theme(\'colors\')', SearchAndReplace::NO_ESCAPE);
158158
$this->searchAndReplace->perform('textColor:\s*colors', 'textColor: theme => theme(\'colors\')', SearchAndReplace::NO_ESCAPE);
159159
$this->searchAndReplace->perform('borderColor:\s*g([^\n]+)', "borderColor: theme => {\nreturn global.Object.assign({ default: theme('colors.gray.300', 'currentColor') }, theme('colors'))\n},", SearchAndReplace::NO_ESCAPE);

src/ConsoleHelper.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct(OutputInterface $output, $recursive, $overwrite, $ex
2323

2424
public function folderConvert($folderPath)
2525
{
26-
$this->output->writeln('<question>Start Converting Folder: </question>' . $folderPath);
26+
$this->output->writeln('<question>Start Converting Folder: </question>'.$folderPath);
2727

2828
if ($this->recursive) {
2929
$iterator = new \RecursiveIteratorIterator(
@@ -53,7 +53,7 @@ public function fileConvert($filePath, $extension)
5353
$filePath = realpath($filePath);
5454

5555
if (!is_file($filePath)) {
56-
$this->output->writeln('<comment>Couldn\'t convert: </comment>' . basename($filePath));
56+
$this->output->writeln('<comment>Couldn\'t convert: </comment>'.basename($filePath));
5757

5858
return;
5959
}
@@ -65,7 +65,7 @@ public function fileConvert($filePath, $extension)
6565
if ($lastDotPosition !== false && !$this->overwrite) {
6666
$newFilePath = substr_replace($filePath, '.tw', $lastDotPosition, 0);
6767
} elseif (!$this->overwrite) {
68-
$newFilePath = $filePath . '.tw';
68+
$newFilePath = $filePath.'.tw';
6969
} else {
7070
// Set the new path to the old path to make sure we overwrite it
7171
$newFilePath = $filePath;
@@ -78,11 +78,11 @@ public function fileConvert($filePath, $extension)
7878
->get();
7979

8080
if ($content !== $newContent) {
81-
$this->output->writeln('<info>Converted: </info>' . basename($newFilePath));
81+
$this->output->writeln('<info>Converted: </info>'.basename($newFilePath));
8282

8383
file_put_contents($newFilePath, $newContent);
8484
} else {
85-
$this->output->writeln('<comment>Nothing to convert: </comment>' . basename($filePath));
85+
$this->output->writeln('<comment>Nothing to convert: </comment>'.basename($filePath));
8686
}
8787
}
8888

@@ -93,7 +93,7 @@ public function codeConvert($code)
9393
->convert()
9494
->get();
9595

96-
$this->output->writeln('<info>Converted Code: </info>' . $convertedCode);
96+
$this->output->writeln('<info>Converted Code: </info>'.$convertedCode);
9797
}
9898

9999
public function fixTailwindConfig($filePath)
@@ -109,7 +109,7 @@ public function fixTailwindConfig($filePath)
109109
if ($lastDotPosition !== false && !$this->overwrite) {
110110
$newFilePath = substr_replace($filePath, '.tw', $lastDotPosition, 0);
111111
} elseif (!$this->overwrite) {
112-
$newFilePath = $filePath . '.tw';
112+
$newFilePath = $filePath.'.tw';
113113
} else {
114114
// Set the new path to the old path to make sure we overwrite it
115115
$newFilePath = $filePath;

src/SearchAndReplace.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ public function perform($search, $replace, $options = null)
124124
) {
125125
$currentSubstitute++;
126126
foreach (['regex_string' => '[a-zA-Z0-9]+', 'regex_number' => '[0-9]+', 'regex_line' => '[^\n]+'] as $regexName => $regexValue) {
127-
$regexMatchCount = preg_match_all('/\\\\?\{' . $regexName . '\\\\?\}/', $search);
128-
$search = preg_replace('/\\\\?\{' . $regexName . '\\\\?\}/', '(?<' . substr($regexName, 6) . '_' . $currentSubstitute . '>' . $regexValue . ')', $search, 1);
129-
$replace = preg_replace('/\\\\?\{' . $regexName . '\\\\?\}/', '${' . substr($regexName, 6) . '_' . $currentSubstitute . '}', $replace, $regexMatchCount > 1 ? 1 : -1);
127+
$regexMatchCount = preg_match_all('/\\\\?\{'.$regexName.'\\\\?\}/', $search);
128+
$search = preg_replace('/\\\\?\{'.$regexName.'\\\\?\}/', '(?<'.substr($regexName, 6).'_'.$currentSubstitute.'>'.$regexValue.')', $search, 1);
129+
$replace = preg_replace('/\\\\?\{'.$regexName.'\\\\?\}/', '${'.substr($regexName, 6).'_'.$currentSubstitute.'}', $replace, $regexMatchCount > 1 ? 1 : -1);
130130
}
131131
continue;
132132
}
@@ -136,13 +136,13 @@ public function perform($search, $replace, $options = null)
136136

137137
//class=" given given-md something-given-md"
138138
$this->givenContent = preg_replace_callback(
139-
'/' . $regexStart . '(?<given>(?<![\-_.\w\d])' . $search . '(?![\-_.\w\d]))' . $regexEnd . '/is',
139+
'/'.$regexStart.'(?<given>(?<![\-_.\w\d])'.$search.'(?![\-_.\w\d]))'.$regexEnd.'/is',
140140
function ($match) use ($replace) {
141141
$replace = preg_replace_callback('/\$\{(number|string|line)_(\d+)\}/', function ($m) use ($match) {
142-
return $match[$m[1] . '_' . $m[2]];
142+
return $match[$m[1].'_'.$m[2]];
143143
}, $replace);
144144

145-
return $match['start'] . $replace . $match['end'];
145+
return $match['start'].$replace.$match['end'];
146146
},
147147
$this->givenContent
148148
);

src/Updater.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,14 @@ protected function convertToVersion1_0()
149149

150150
foreach ($classes as $beforeClass => $afterClass) {
151151
$this->searchAndReplace->perform(
152-
($isCSSfile ? '.' : '') . $beforeClass,
153-
($isCSSfile ? '.' : '') . $afterClass,
152+
($isCSSfile ? '.' : '').$beforeClass,
153+
($isCSSfile ? '.' : '').$afterClass,
154154
$isCSSfile ? SearchAndReplace::AFTER_APPLY_DIRECTIVE : SearchAndReplace::INSIDE_CLASSE_PROP
155155
);
156156
}
157157

158158
//empty variant
159-
$this->searchAndReplace->perform(($isCSSfile ? '\.' : '(?>[a-z]+:)?') . 'no-underline', '', SearchAndReplace::NO_ESCAPE);
160-
159+
$this->searchAndReplace->perform(($isCSSfile ? '\.' : '(?>[a-z]+:)?').'no-underline', '', SearchAndReplace::NO_ESCAPE);
161160

162161
if ($isCSSfile) {
163162
return;

0 commit comments

Comments
 (0)