Skip to content

Commit

Permalink
Add Prettier code formatting for starter templates (#11)
Browse files Browse the repository at this point in the history
* Add Prettier config for formatting all templates
* Format projects: angular, js, node, react, react-ts, rxjs, typescript, vue
* Add GitHub action to check code formatting
  • Loading branch information
Florens Verschelde authored Aug 25, 2023
1 parent 76eaa12 commit 16ede6d
Show file tree
Hide file tree
Showing 29 changed files with 463 additions and 116 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Check code formatting

on:
pull_request:
push:
branches: [main]

jobs:
prettier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
- run: npm ci
- run: npm run format:check
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Ignore patterns for repo config
/node_modules

# Ignore patterns for templates
*/node_modules
#*/package-lock.json
*/yarn.lock
*/pnpm-lock.yaml
35 changes: 35 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Ignore repository config
/*.*
/LICENSE

# Ignore specific templates
/bootstrap-5
/egg
/express-simple
/graphql
/gsap-*
/json-graphql-server
/json-server
/koa
/nextjs
/nodemon
/quasar
/slidev
/sveltekit
/tres

# Ignore specific file formats
# Prettier formatting of HTML is questionable, let's skip it for now
**/*.html
# Skipping Markdown as well, as it may contain custom DSLs that Prettier doesn't handle well
**/*.md
**/*.mdx
# Maybe skip formatting templating languages too
**/*.svelte
**/*.vue

# We maybe don't want to have those files in the first place?
**/dist/*
**/build/*
**/.vscode/*
**/package-lock.json
18 changes: 18 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"printWidth": 80,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"useTabs": false,
"plugins": ["prettier-plugin-svelte"],
"overrides": [
{
"files": ["**/.stackblitzrc"],
"options": { "parser": "json" }
},
{
"files": ["**/*.svelte"],
"options": { "parser": "svelte" }
}
]
}
24 changes: 6 additions & 18 deletions angular/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@
"main": "src/main.ts",
"outputPath": "dist/demo",
"scripts": [],
"styles": [
"src/global_styles.css"
],
"styles": ["src/global_styles.css"],
"tsConfig": "src/tsconfig.app.json"
}
},
Expand All @@ -56,13 +54,8 @@
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"exclude": [
"**/node_modules/**"
],
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
]
"exclude": ["**/node_modules/**"],
"tsConfig": ["src/tsconfig.app.json", "src/tsconfig.spec.json"]
}
},
"serve": {
Expand All @@ -80,17 +73,12 @@
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"assets": [
"src/favicon.ico",
"src/assets"
],
"assets": ["src/favicon.ico", "src/assets"],
"karmaConfig": "src/karma.conf.js",
"main": "src/test.ts",
"polyfills": [],
"scripts": [],
"styles": [
"styles.css"
],
"styles": ["styles.css"],
"tsConfig": "src/tsconfig.spec.json"
}
}
Expand All @@ -103,4 +91,4 @@
}
},
"version": 1
}
}
2 changes: 1 addition & 1 deletion angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
"karma-jasmine-html-reporter": "~1.7.0",
"typescript": "~4.9.0"
}
}
}
8 changes: 4 additions & 4 deletions angular/src/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ module.exports = function (config) {
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage/my-app'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
fixWebpackSourcePaths: true,
},
reporters: ['progress', 'kjhtml'],
port: 9876,
Expand All @@ -27,6 +27,6 @@ module.exports = function (config) {
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
restartOnFileChange: true,
});
};
4 changes: 2 additions & 2 deletions angular/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { bootstrapApplication } from '@angular/platform-browser';
standalone: true,
imports: [CommonModule],
template: `
<h1>Hello from {{name}}!</h1>
<h1>Hello from {{ name }}!</h1>
<a target="_blank" href="https://angular.io/start">
Learn more about Angular
Learn more about Angular
</a>
`,
})
Expand Down
9 changes: 2 additions & 7 deletions angular/src/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
"outDir": "../out-tsc/app",
"types": []
},
"files": [
"main.ts",
"polyfills.ts"
],
"include": [
"**/*.d.ts"
]
"files": ["main.ts", "polyfills.ts"],
"include": ["**/*.d.ts"]
}
15 changes: 3 additions & 12 deletions angular/src/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,8 @@
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/spec",
"types": [
"jasmine",
"node"
]
"types": ["jasmine", "node"]
},
"files": [
"test.ts",
"polyfills.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
"files": ["test.ts", "polyfills.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]
}
2 changes: 1 addition & 1 deletion js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import './style.css';

// Write Javascript code!
const appDiv = document.getElementById('app');
appDiv.innerHTML = `<h1>JS Starter</h1>`;
appDiv.innerHTML = `<h1>JS Starter</h1>`;
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"version": "0.0.0",
"private": true,
"dependencies": {}
}
}
5 changes: 3 additions & 2 deletions js/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
h1, h2 {
h1,
h2 {
font-family: Lato;
}
}
2 changes: 1 addition & 1 deletion js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"compilerOptions": {
"target": "esnext"
}
}
}
2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}
}
Loading

0 comments on commit 16ede6d

Please sign in to comment.