Skip to content

Commit 33b18c7

Browse files
committed
feat(scripts): allow Prettier to format more files (YAML, Markdown)
We're not going to change the default globs in liferay-portal yet (or possibly ever?) because the Java Source Formatter currently handles these types. However, we can make it easier for non-liferay-portal projects like liferay-learn: https://github.com/liferay/liferay-learn that use liferay-npm-scripts to run Prettier over a broader range of files. It's a simple matter of expanding the list of allowed globs. Test plan: In order to actually test this I had these two PRs applied: - #101 - #102 Then, with this npmscripts.config.js at the top level of the monorepo: module.exports = { check: ['**/*.{md,ts,yml}'], fix: ['**/*.{md,ts,yml}'], } I created some bad files and ran `projects/npm-tools/packages/npm-scripts/bin/liferay-npm-scripts.js check` and saw these errors: x.md: BAD x.ts: BAD x.yml: BAD and then ran `check` and saw them get fixed. Then, for good measure, in a liferay-learn clone, I added "yml" and "md" to the globs in the npmscripts.config.js and repeated the test after a: npm install cp -R path/to/npm-scripts node_modules/@liferay/ ie. npm run format:check see: site/homepage/x.md: BAD site/homepage/x.yml: BAD Prettier checked 21 files, 2 files have problems Then: npm run format and see the errors fixed: Prettier checked 21 files, fixed 2 files Closes: #92
1 parent bd80ca9 commit 33b18c7

File tree

1 file changed

+14
-2
lines changed
  • projects/npm-tools/packages/npm-scripts/src/scripts

1 file changed

+14
-2
lines changed

projects/npm-tools/packages/npm-scripts/src/scripts/format.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,21 @@ const DEFAULT_OPTIONS = {
1818
};
1919

2020
/**
21-
* File extensions that we want Prettier to process.
21+
* File extensions that we allow Prettier to process.
2222
*/
23-
const EXTENSIONS = ['.js', '.json', '.jsp', '.jspf', '.scss', '.ts', '.tsx'];
23+
const EXTENSIONS = [
24+
'.js',
25+
'.json',
26+
'.jsp',
27+
'.jspf',
28+
'.md',
29+
'.markdown',
30+
'.scss',
31+
'.ts',
32+
'.tsx',
33+
'.yml',
34+
'.yaml',
35+
];
2436

2537
const IGNORE_FILE = '.prettierignore';
2638

0 commit comments

Comments
 (0)