Skip to content

Commit

Permalink
Do not force VS Code settings (#37498)
Browse files Browse the repository at this point in the history
* Suggest VS Code settings

* Remove hard-coded VS Code settings

* Update .gitignore

* Add simple VS Code symlink script

* Add VS Code task

* Update tools/install-vscode-settings.sh

Co-authored-by: Brad Jorsch <[email protected]>

* Add prettier config back

* Copy instead of symlink

* Update comment

* Rename to a .jsonc file

* Add some comments

* Add "managed" comment to file

* Detect managed vs. custom settings

* Add schema for settings autocomplete

---------

Co-authored-by: Brad Jorsch <[email protected]>
  • Loading branch information
tbradsha and anomiex authored Jun 14, 2024
1 parent 18bd944 commit bd01379
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
vendor/
jetpack_vendor/
/.nova/
/.vscode/
/logs
/allure-results/

## FILES
.DS_Store
*.code-workspace
*.swp
# Custom environment for Docker compose (used by docker-compose.yml)
/.env
Expand Down Expand Up @@ -56,4 +54,6 @@ phpcs.xml
# This file indicates we're in draft mode, which reduces checks
.jetpack-draft

.vscode/settings.json
# VS Code setting files
*.code-workspace
/.vscode/settings.json
31 changes: 16 additions & 15 deletions .vscode/settings.json → .vscode/settings.dist.jsonc
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
// This is a managed VS Code settings file.
// It is copied into place by `tools/install-vscode-settings.sh`.
// If you no longer want the settings managed, remove these comments.
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
// Define schema to allow auto-completion.
"$schema": "vscode://schemas/settings/workspace",
// Don't show these files in VS Code.
"files.exclude": {
"**/.DS_Store/**": true
},
// Don't search these files in VS Code.
"search.exclude": {
"**/.cache/**": true,
"**/.DS_Store/**": true,
"**/.git/**": true,
"**/.hg/**": true,
"**/.svn/**": true,
"**/bower_components/**": true,
"**/CVS/**": true,
"**/jetpack_vendor/**": true,
"**/node_modules/**": true,
"**/vendor/**": true,
"**/vendor/**": true
},
// Don't run Intelephense on these files.
"intelephense.files.exclude": [
"**/.cache/**",
"**/.git/**",
"**/.svn/**",
"**/.hg/**",
"**/.history/**",
"**/bower_components/**",
"**/jetpack_vendor/**",
"**/packages/**/wordpress/**",
"**/projects/**/wordpress/**",
"**/plugins/**/wordpress/**",
"**/vendor/**",
"**/vendor/**"
],
"phpCodeSniffer.autoExecutable": true,
"phpCodeSniffer.standard": "Automatic",
// Have PHPCS ignore these files.
"phpCodeSniffer.exclude": [
"**/.git/**",
"**/.svn/**",
"**/.hg/**",
"**/.cache/**",
"**/jetpack_vendor/**",
"**/vendor/**",
"**/vendor/**"
],
// Use this wp-prettier from this path.
"prettier.prettierPath": "tools/js-tools/node_modules/prettier/index.cjs"
}
20 changes: 20 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Install VS Code settings",
"type": "shell",
"command": "./tools/install-vscode-settings.sh",
"runOptions": {
"runOn": "folderOpen"
},
"problemMatcher": [],
"presentation": {
"reveal": "silent",
"close": true
}
}
]
}
43 changes: 43 additions & 0 deletions tools/install-vscode-settings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
# This script allows a user to install repo-recommended VS Code settings.
# See: p1HpG7-sQE-p2
#
# Exit codes:
# 0: All is well
# 1: Repo settings template is missing
# 2: Settings file creation failed

# Go to monorepo root.
cd "$(dirname "${BASH_SOURCE[0]}")/.."

template_file=.vscode/settings.dist.jsonc
dest_file=.vscode/settings.json

# Abort if repo settings file is missing.
if [[ ! -f "$template_file" ]]; then
echo "Repo settings template is missing; aborting."
exit 1
fi

# Abort if settings file already exists and managed comment is missing.
managed_comment='// This is a managed VS Code settings file.'
if [[ -f "$dest_file" ]]; then
if diff -q "$template_file" "$dest_file" > /dev/null; then
echo 'Managed settings are up to date; no changes needed.'
exit
elif [[ $(head -1 "$dest_file") != "$managed_comment" ]]; then
echo "Custom settings file; aborting."
exit
fi
fi

# Copy file into place.
cp "$template_file" "$dest_file"

# Verify success.
if [[ ! -f "$dest_file" ]] || ! diff -q "$template_file" "$dest_file" > /dev/null; then
echo "Error copying settings into place!"
exit 2
fi

echo "Copied managed settings into place."

0 comments on commit bd01379

Please sign in to comment.