Commit 953608ac authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch '44771-prettier-seems-to-ignore-the-overrides-2' into 'master'

Resolve "Prettier seems to ignore the `overrides`"

Closes #44771

See merge request gitlab-org/gitlab-ce!19153
parents 5297e94d e04dfff8
...@@ -43,3 +43,17 @@ yarn prettier-all-save ...@@ -43,3 +43,17 @@ yarn prettier-all-save
Formats all files in the repository with Prettier. (This should only be used to test global rule updates otherwise you would end up with huge MR's). Formats all files in the repository with Prettier. (This should only be used to test global rule updates otherwise you would end up with huge MR's).
The source of these Yarn scripts can be found in `/scripts/frontend/prettier.js`. The source of these Yarn scripts can be found in `/scripts/frontend/prettier.js`.
### Scripts during Conversion period
```
node ./scripts/frontend/prettier.js check ./vendor/
```
This will go over all files in a specific folder check it.
```
node ./scripts/frontend/prettier.js save ./vendor/
```
This will go over all files in a specific folder and save it.
...@@ -9,6 +9,8 @@ const getStagedFiles = require('./frontend_script_utils').getStagedFiles; ...@@ -9,6 +9,8 @@ const getStagedFiles = require('./frontend_script_utils').getStagedFiles;
const mode = process.argv[2] || 'check'; const mode = process.argv[2] || 'check';
const shouldSave = mode === 'save' || mode === 'save-all'; const shouldSave = mode === 'save' || mode === 'save-all';
const allFiles = mode === 'check-all' || mode === 'save-all'; const allFiles = mode === 'check-all' || mode === 'save-all';
let dirPath = process.argv[3] || '';
if (dirPath && dirPath.charAt(dirPath.length - 1) !== '/') dirPath += '/';
const config = { const config = {
patterns: ['**/*.js', '**/*.vue', '**/*.scss'], patterns: ['**/*.js', '**/*.vue', '**/*.scss'],
...@@ -39,9 +41,10 @@ prettierIgnore.add( ...@@ -39,9 +41,10 @@ prettierIgnore.add(
const availableExtensions = Object.keys(config.parsers); const availableExtensions = Object.keys(config.parsers);
console.log(`Loading ${allFiles ? 'All' : 'Staged'} Files ...`); console.log(`Loading ${allFiles ? 'All' : 'Selected'} Files ...`);
const stagedFiles = allFiles ? null : getStagedFiles(availableExtensions.map(ext => `*.${ext}`)); const stagedFiles =
allFiles || dirPath ? null : getStagedFiles(availableExtensions.map(ext => `*.${ext}`));
if (stagedFiles) { if (stagedFiles) {
if (!stagedFiles.length || (stagedFiles.length === 1 && !stagedFiles[0])) { if (!stagedFiles.length || (stagedFiles.length === 1 && !stagedFiles[0])) {
...@@ -60,6 +63,13 @@ if (allFiles) { ...@@ -60,6 +63,13 @@ if (allFiles) {
const patterns = config.patterns; const patterns = config.patterns;
const globPattern = patterns.length > 1 ? `{${patterns.join(',')}}` : `${patterns.join(',')}`; const globPattern = patterns.length > 1 ? `{${patterns.join(',')}}` : `${patterns.join(',')}`;
files = glob.sync(globPattern, { ignore }).filter(f => allFiles || stagedFiles.includes(f)); files = glob.sync(globPattern, { ignore }).filter(f => allFiles || stagedFiles.includes(f));
} else if (dirPath) {
const ignore = config.ignore;
const patterns = config.patterns.map(item => {
return dirPath + item;
});
const globPattern = patterns.length > 1 ? `{${patterns.join(',')}}` : `${patterns.join(',')}`;
files = glob.sync(globPattern, { ignore });
} else { } else {
files = stagedFiles.filter(f => availableExtensions.includes(f.split('.').pop())); files = stagedFiles.filter(f => availableExtensions.includes(f.split('.').pop()));
} }
...@@ -73,12 +83,11 @@ if (!files.length) { ...@@ -73,12 +83,11 @@ if (!files.length) {
console.log(`${shouldSave ? 'Updating' : 'Checking'} ${files.length} file(s)`); console.log(`${shouldSave ? 'Updating' : 'Checking'} ${files.length} file(s)`);
prettier files.forEach(file => {
.resolveConfig('.')
.then(options => {
console.log('Found options : ', options);
files.forEach(file => {
try { try {
prettier
.resolveConfig(file)
.then(options => {
const fileExtension = file.split('.').pop(); const fileExtension = file.split('.').pop();
Object.assign(options, { Object.assign(options, {
parser: config.parsers[fileExtension], parser: config.parsers[fileExtension],
...@@ -101,17 +110,17 @@ prettier ...@@ -101,17 +110,17 @@ prettier
} }
console.log(`Prettify Manually : ${file}`); console.log(`Prettify Manually : ${file}`);
} }
})
.catch(e => {
console.log(`Error on loading the Config File: ${e.message}`);
process.exit(1);
});
} catch (error) { } catch (error) {
didError = true; didError = true;
console.log(`\n\nError with ${file}: ${error.message}`); console.log(`\n\nError with ${file}: ${error.message}`);
} }
}); });
if (didWarn || didError) { if (didWarn || didError) {
process.exit(1); process.exit(1);
} }
})
.catch(e => {
console.log(`Error on loading the Config File: ${e.message}`);
process.exit(1);
});
...@@ -270,11 +270,7 @@ acorn@^3.0.4: ...@@ -270,11 +270,7 @@ acorn@^3.0.4:
version "3.3.0" version "3.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a" resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a"
acorn@^5.0.0, acorn@^5.3.0: acorn@^5.0.0, acorn@^5.3.0, acorn@^5.5.0:
version "5.5.3"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.5.3.tgz#f473dd47e0277a08e28e9bec5aeeb04751f0b8c9"
acorn@^5.5.0:
version "5.6.2" version "5.6.2"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.6.2.tgz#b1da1d7be2ac1b4a327fb9eab851702c5045b4e7" resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.6.2.tgz#b1da1d7be2ac1b4a327fb9eab851702c5045b4e7"
...@@ -4002,14 +3998,10 @@ icss-utils@^2.1.0: ...@@ -4002,14 +3998,10 @@ icss-utils@^2.1.0:
dependencies: dependencies:
postcss "^6.0.1" postcss "^6.0.1"
ieee754@^1.1.11: ieee754@^1.1.11, ieee754@^1.1.4:
version "1.1.11" version "1.1.11"
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.11.tgz#c16384ffe00f5b7835824e67b6f2bd44a5229455" resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.11.tgz#c16384ffe00f5b7835824e67b6f2bd44a5229455"
ieee754@^1.1.4:
version "1.1.8"
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.8.tgz#be33d40ac10ef1926701f6f08a2d86fbfd1ad3e4"
iferr@^0.1.5: iferr@^0.1.5:
version "0.1.5" version "0.1.5"
resolved "https://registry.yarnpkg.com/iferr/-/iferr-0.1.5.tgz#c60eed69e6d8fdb6b3104a1fcbca1c192dc5b501" resolved "https://registry.yarnpkg.com/iferr/-/iferr-0.1.5.tgz#c60eed69e6d8fdb6b3104a1fcbca1c192dc5b501"
...@@ -6247,11 +6239,7 @@ preserve@^0.2.0: ...@@ -6247,11 +6239,7 @@ preserve@^0.2.0:
version "0.2.0" version "0.2.0"
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
prettier@1.11.1: prettier@1.12.1, prettier@^1.11.1:
version "1.11.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.11.1.tgz#61e43fc4cd44e68f2b0dfc2c38cd4bb0fccdcc75"
prettier@^1.11.1:
version "1.12.1" version "1.12.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.12.1.tgz#c1ad20e803e7749faf905a409d2367e06bbe7325" resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.12.1.tgz#c1ad20e803e7749faf905a409d2367e06bbe7325"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment