Skip to content

Commit

Permalink
chore: add prettier to pre-commit for markdown and json files (#4846)
Browse files Browse the repository at this point in the history
  • Loading branch information
philprime authored Feb 18, 2025
1 parent 43a41b3 commit 979e024
Show file tree
Hide file tree
Showing 117 changed files with 87,257 additions and 86,710 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/format-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ jobs:
- name: Install Clang-Format
run: brew install clang-format
- run: swiftlint --version
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- run: corepack enable
- run: yarn install
- name: Format Code
run: make format

Expand Down
20 changes: 18 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ on:
- "Samples/**"
- ".github/workflows/lint.yml"
- "scripts/ci-select-xcode.sh"

- "*.json"
- "*.md"

pull_request:
paths:
- "Sources/**"
Expand All @@ -22,7 +24,9 @@ on:
- "Sentry.xcodeproj/**"
- "*.podspec"
- "Gemfile.lock"

- "*.json"
- "*.md"

# https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand Down Expand Up @@ -82,3 +86,15 @@ jobs:
- uses: actions/checkout@v4
- run: brew install shellcheck
- run: shellcheck **/*.sh

lint-prettier:
name: Run Prettier
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- run: corepack enable
- run: yarn install
- run: yarn prettier --check --ignore-unknown --config .prettierrc "**/*.{md,json}"
144 changes: 143 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,149 @@ Package.resolved
/rule_docs/

# Visual Studio Code
.vscode/
.vscode/*
!.vscode/extensions.json

Cartfile.resolved
*.log

#################
#### Node.JS ####
#################

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# vitepress build output
**/.vitepress/dist

# vitepress cache directory
**/.vitepress/cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22.13.1
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,21 @@ repos:
types_or: ["swift", "objective-c", "objective-c++", "c", "c++" ]
args:
- "lint"

- id: format-markdown
name: Format Markdown
description: 'Format Markdown'
language: node
files: ^.*\.md$
types_or: [markdown]
entry: prettier --write --ignore-unknown --config .prettierrc
additional_dependencies: ["[email protected]"]

- id: format-json
name: Format JSON
description: 'Format JSON'
language: node
files: ^.*\.json$
types_or: [json]
entry: prettier --write --ignore-unknown --config .prettierrc
additional_dependencies: ["[email protected]"]
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tests/Resources/**/*garbage*.json
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"tabWidth": 2,
"useTabs": false
}
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode"]
}
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ init:
clang-format --version | awk '{print $$3}' > scripts/.clang-format-version
swiftlint version > scripts/.swiftlint-version

# The node version manager is optional, so we don't fail if it's not installed.
if [ -n "$NVM_DIR" ] && [ -d "$NVM_DIR" ]; then nvm use; fi
# The corepack is optional, so we don't fail if it's not installed.
if ! command -v corepack > /dev/null; then corepack enable; fi

yarn install

# installs the tools needed to run CI test tasks locally
.PHONY: init-ci-test
init-ci-test:
Expand All @@ -27,9 +34,10 @@ lint:
@echo "--> Running Swiftlint and Clang-Format"
./scripts/check-clang-format.py -r Sources Tests
swiftlint --strict
yarn prettier --check --ignore-unknown --config .prettierrc "**/*.{md,json}"
.PHONY: lint

format: format-clang format-swift
format: format-clang format-swift format-markdown format-json

# Format ObjC, ObjC++, C, and C++
format-clang:
Expand All @@ -41,6 +49,13 @@ format-clang:
format-swift:
swiftlint --fix

# Format Markdown
format-markdown:
yarn prettier --write --ignore-unknown --config .prettierrc "**/*.md"

# Format JSON
format-json:
yarn prettier --write --ignore-unknown --config .prettierrc "**/*.json"

## Current git reference name
GIT-REF := $(shell git rev-parse --abbrev-ref HEAD)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"colors" : [
"colors": [
{
"idiom" : "universal"
"idiom": "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
"info": {
"author": "xcode",
"version": 1
}
}
Loading

0 comments on commit 979e024

Please sign in to comment.