Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maint: Add prettier pre-commit hook #3663

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 55 additions & 55 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,61 @@ BasedOnStyle: Mozilla
Language: Cpp
Standard: c++17

AccessModifierOffset: '-4'
AccessModifierOffset: "-4"
AlignAfterOpenBracket: BlockIndent
AlignEscapedNewlinesLeft: 'false'
AlignEscapedNewlinesLeft: "false"
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: 'false'
AllowShortCaseLabelsOnASingleLine: 'false'
AllowShortFunctionsOnASingleLine: 'false'
AllowShortIfStatementsOnASingleLine: 'false'
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakTemplateDeclarations: 'true'
AllowShortBlocksOnASingleLine: "false"
AllowShortCaseLabelsOnASingleLine: "false"
AllowShortFunctionsOnASingleLine: "false"
AllowShortIfStatementsOnASingleLine: "false"
AllowShortLoopsOnASingleLine: "false"
AlwaysBreakTemplateDeclarations: "true"
BinPackArguments: false
BinPackParameters: false
BreakAfterAttributes: Leave
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: 'true'
BreakConstructorInitializersBeforeComma: 'true'
BreakStringLiterals: 'false'
ColumnLimit: '100'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'false'
ConstructorInitializerIndentWidth: '4'
ContinuationIndentWidth: '4'
Cpp11BracedListStyle: 'false'
DerivePointerAlignment: 'false'
DisableFormat: 'false'
BreakBeforeTernaryOperators: "true"
BreakConstructorInitializersBeforeComma: "true"
BreakStringLiterals: "false"
ColumnLimit: "100"
ConstructorInitializerAllOnOneLineOrOnePerLine: "false"
ConstructorInitializerIndentWidth: "4"
ContinuationIndentWidth: "4"
Cpp11BracedListStyle: "false"
DerivePointerAlignment: "false"
DisableFormat: "false"
EmptyLineAfterAccessModifier: Always
EmptyLineBeforeAccessModifier: Always
ExperimentalAutoDetectBinPacking: 'true'
ExperimentalAutoDetectBinPacking: "true"
IncludeBlocks: Regroup
IncludeCategories:
- Regex: <[^.]+>
Priority: -3
- Regex: <mamba/.+>
Priority: -1
- Regex: <.+>
Priority: -2
- Regex: '"mamba/.+"'
Priority: 0
- Regex: '"solv-cpp/.+"'
Priority: 0
- Regex: '".+/.+"'
Priority: 1
- Regex: '".+"'
Priority: 2
IndentCaseLabels: 'true'
IndentWidth: '4'
IndentWrappedFunctionNames: 'false'
InsertBraces: true # Experimental
KeepEmptyLinesAtTheStartOfBlocks: 'false'
MaxEmptyLinesToKeep: '2'
- Regex: <[^.]+>
Priority: -3
- Regex: <mamba/.+>
Priority: -1
- Regex: <.+>
Priority: -2
- Regex: '"mamba/.+"'
Priority: 0
- Regex: '"solv-cpp/.+"'
Priority: 0
- Regex: '".+/.+"'
Priority: 1
- Regex: '".+"'
Priority: 2
IndentCaseLabels: "true"
IndentWidth: "4"
IndentWrappedFunctionNames: "false"
InsertBraces: true # Experimental
KeepEmptyLinesAtTheStartOfBlocks: "false"
MaxEmptyLinesToKeep: "2"
NamespaceIndentation: All
ObjCBlockIndentWidth: '4'
ObjCSpaceAfterProperty: 'false'
ObjCSpaceBeforeProtocolList: 'false'
ObjCBlockIndentWidth: "4"
ObjCSpaceAfterProperty: "false"
ObjCSpaceBeforeProtocolList: "false"
PackConstructorInitializers: Never
PenaltyBreakAssignment: 100000
PenaltyBreakBeforeFirstCallParameter: 0
Expand All @@ -67,22 +67,22 @@ PenaltyExcessCharacter: 10
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 10
PointerAlignment: Left
QualifierAlignment: Custom # Experimental
QualifierAlignment: Custom # Experimental
QualifierOrder: [inline, static, constexpr, const, volatile, type]
ReflowComments: 'true'
ReflowComments: "true"
SeparateDefinitionBlocks: Always
SortIncludes: CaseInsensitive
SortUsingDeclarations: Never
SpaceAfterCStyleCast: 'true'
SpaceAfterTemplateKeyword: 'true'
SpaceBeforeAssignmentOperators: 'true'
SpaceAfterCStyleCast: "true"
SpaceAfterTemplateKeyword: "true"
SpaceBeforeAssignmentOperators: "true"
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: 'false'
SpacesBeforeTrailingComments: '2'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInContainerLiterals: 'false'
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
TabWidth: '4'
SpaceInEmptyParentheses: "false"
SpacesBeforeTrailingComments: "2"
SpacesInAngles: "false"
SpacesInCStyleCastParentheses: "false"
SpacesInContainerLiterals: "false"
SpacesInParentheses: "false"
SpacesInSquareBrackets: "false"
TabWidth: "4"
UseTab: Never
8 changes: 4 additions & 4 deletions .github/actions/workspace/action.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: workspace
description: 'A action to persist your workspace across different jobs'
description: "A action to persist your workspace across different jobs"
branding:
icon: 'box'
color: 'green'
icon: "box"
color: "green"
inputs:
action:
required: true
Expand All @@ -18,7 +18,7 @@ inputs:
required: true
default: ${{ github.workflow }}-${{ github.run_id }}-${{ github.run_number }}-${{ github.sha }}
key_suffix:
default: ''
default: ""
token:
required: false
default: ${{ github.token }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/bot_issue_template.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
title: Bot failure
---

There was a problem with the **{{ workflow }}** workflow, please investigate.
24 changes: 12 additions & 12 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ jobs:
env:
PRE_COMMIT_USE_MICROMAMBA: 1
steps:
- uses: actions/checkout@v4
- name: Install pre-commit
uses: mamba-org/setup-micromamba@v2
with:
environment-name: linters
create-args: pre-commit
- name: Add micromamba to GITHUB_PATH
run: echo "${HOME}/micromamba-bin" >> $GITHUB_PATH
- name: Run all linters
shell: micromamba-shell {0}
run: |
pre-commit run --all-files --verbose --show-diff-on-failure
- uses: actions/checkout@v4
- name: Install pre-commit
uses: mamba-org/setup-micromamba@v2
with:
environment-name: linters
create-args: pre-commit
- name: Add micromamba to GITHUB_PATH
run: echo "${HOME}/micromamba-bin" >> $GITHUB_PATH
- name: Run all linters
shell: micromamba-shell {0}
run: |
pre-commit run --all-files --verbose --show-diff-on-failure
18 changes: 9 additions & 9 deletions .github/workflows/static_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ on:
branches:
- main
paths-ignore:
- 'docs/**'
- 'mamba/**'
- 'libmambapy/**'
- '**.md'
- "docs/**"
- "mamba/**"
- "libmambapy/**"
- "**.md"
merge_group:
types: [checks_requested]

Expand All @@ -27,11 +27,11 @@ jobs:
fail-fast: false
matrix:
include:
- {os: ubuntu-latest, platform: linux, arch: "64"}
- {os: ubuntu-latest, platform: linux, arch: aarch64}
- {os: ubuntu-latest, platform: linux, arch: ppc64le}
- {os: macos-latest, platform: osx, arch: "64"}
- {os: macos-latest, platform: osx, arch: arm64}
- { os: ubuntu-latest, platform: linux, arch: "64" }
- { os: ubuntu-latest, platform: linux, arch: aarch64 }
- { os: ubuntu-latest, platform: linux, arch: ppc64le }
- { os: macos-latest, platform: osx, arch: "64" }
- { os: macos-latest, platform: osx, arch: arm64 }
steps:
- name: Checkout micromamba-feedstock
uses: actions/checkout@v4
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ on:
branches:
- main
paths-ignore:
- 'docs/**'
- '**.md'
- "docs/**"
- "**.md"
merge_group:
types: [checks_requested]


concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Expand Down
23 changes: 10 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@ repos:
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: fix-encoding-pragma
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is deprecated

args: [--remove]
- id: check-yaml
exclude: ^.+(/tests/|/recipe/).+$
- id: check-toml
- id: check-json
- id: check-merge-conflict
- id: pretty-format-json
args: [--autofix]
Comment on lines -10 to -16
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These checks (except check-merge-conflict) no longer seem to be needed

- id: debug-statements
language_version: python3
# Autoformat: YAML, JSON, Markdown, etc.
- repo: https://github.com/rbubley/mirrors-prettier
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a fork, since official prettier pre-commit hook has been archived:
http://github.com/prettier/prettier/issues/15742

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, I'm kind of reluctant here. As I'm in favor of general improvements, using something that just has been archived (even if a mirror is available) doesn't seem a good idea to me.
https://github.com/rbubley/mirrors-prettier seems to rather be a workaround to let people keep using the hook and there are no guarantees that it will be maintained in the long term.
I would highly suggest to wait until a stable solution is available (could be something used by a significant number of people, regularly maintained, or officially superseding the archived one in pre-commit).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an important gotcha: the https://github.com/rbubley/mirrors-prettier is not a mirror/fork of prettier ore pre-commit.
It's a small repo to make vanilla prettier work as pre-commit hook.
If you take a look at the source code, you'll see that the part which matters is less than 100 lines.
So, there is not much to maintain and the code to automatically update the version of the prettier is already there.

Even in the worst case scenario, this fork will stop updating, we will have some prettier version in this repo.
It's already working great for lots of files like json/yaml/toml/markdown.
I don't think these files have that much new syntax features added to them (unlike python/c++ code, where you really want tools to work with newer code as well).
So, it's unlikely we'll encounter issues due to not using the latest version.

And the sooner we add prettier, the less diff this PR will generate.

rev: v3.4.2
hooks:
- id: prettier
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
- id: rst-backticks
Comment on lines 18 to +19
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This an example when existing hooks allow different styles (even in the same file)

- id: rst-directive-colons
- id: rst-inline-touching-normal
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
hooks:
Expand All @@ -31,7 +28,7 @@ repos:
rev: v0.8.2
hooks:
- id: ruff
args: [ --fix ]
args: [--fix]
- id: ruff-format
- repo: https://github.com/asottile/blacken-docs
rev: 1.19.1
Expand All @@ -55,4 +52,4 @@ repos:
exclude: (CHANGELOG.md)
# In case of ambiguity (multiple possible corrections), `typos` will just report it to the user and move on without applying/writing any changes.
# cf. https://github.com/crate-ci/typos
args: [ --write-changes ]
args: [--write-changes]
Loading
Loading