Skip to content

Commit

Permalink
Repo cleanup (#509)
Browse files Browse the repository at this point in the history
Handles a number of cleanup tasks
- Fixes autopep8 issue conditions originating from pinning an
`extra_packages` field (see #404). This should fix the issue identified
in #507. I will also fix the
underlying CLI bug separately.
- Updates action descriptions and comments to be clearer and more
standardized (follow-up to #505).
- Rename all repo readme files to all caps. This helps them stand out
more to new users.
- Update the readme instructions to fix broken links and modernize the
instructions with Trunk Tools and other practices.
- Run `trunk upgrade`
  • Loading branch information
TylerJang27 authored and pat-trunk-io committed Jan 22, 2024
1 parent 7e9cefc commit 9717889
Show file tree
Hide file tree
Showing 37 changed files with 118 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/filters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ repo-tests:
- linters/**
- actions/**
- tools/**
- readme.md
- README.md
- .trunk/trunk.yaml
- package.json
- package-lock.json
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/repo_tests.reusable.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Runs tests to verify:
# 1. All linters are specified in the readme.md
# 1. All linters are specified in the README.md
# 2. All linters have test coverage.
# 3. Plugin has a healthy composite config
name: Repo Tests
Expand Down
5 changes: 3 additions & 2 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 0.1

# version used for local trunk runs and testing
cli:
version: 1.16.1-beta.14
version: 1.16.3-beta.8

api:
address: api.trunk-staging.io:8443
Expand All @@ -19,7 +19,6 @@ plugins:

lint:
# enabled linters inherited from github.com/trunk-io/configs plugin
enabled: []

disabled:
- pylint # pylint diagnostics are too strict
Expand All @@ -31,6 +30,8 @@ lint:
- "**/test_data/**"

actions:
# Uncomment to enable more verbose action logs
# output_level: verbose
definitions:
- id: repo-tests
display_name: Repo Tests
Expand Down
70 changes: 53 additions & 17 deletions contributing.md → CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ Thanks for contributing to trunk's default plugins! Read on to learn more.
- [Release process](#releases)
- [Adding new linters](#linters)
- [Adding new actions](#actions)
- [Adding new tools](#tools)
- [Guidelines](#guidelines)
- [Docs](https://docs.trunk.io)

## Overview

We use this repository to provide our users with default linters and actions. trunk automatically
adds the following to users' trunk.yaml:
We use this repository to provide our users with default linters, actions, and tools. Trunk
automatically adds the following to users' trunk.yaml:

```yaml
plugins:
Expand Down Expand Up @@ -49,7 +50,7 @@ plugins:
sources:
- id: trunk
uri: https://github.com/trunk-io/plugins
ref: v0.0.8 # will change to v0.0.9 on next `trunk upgrade`
ref: v1.2.5 # will change to the latest release on next `trunk upgrade`
```

We recommend only setting the above `ref` field to be our released tags, but if you need a linter or
Expand All @@ -64,32 +65,34 @@ load a plugin source until they have upgraded to a compliant CLI version.

To add a new linter:

1. Create a directory inside `linters/` with the name of your new linter.
2. Inside this new directory, create the following structure. If you ran `trunk check` in this
repository recently, some of these files should be automatically created for you:
1. Run `trunk check` to start up Trunk in the background.
2. Create a directory inside `linters/` with the name of your new linter.
3. Inside this new directory, create the following structure. Most of these files will be
automatically created for you:

```text
linters/
└─my-linter/
│ plugin.yaml
│ my_linter.test.ts
readme.md (optional)
README.md (optional)
│ my-config.json (optional)
└─test_data/
└─basic.in.py (with appropriate extension)
```

3. Add your linter definition to `plugin.yaml` (consult the docs for [custom linters] and [custom
parsers] to understand how it should be defined).
4. Making sure the plugin in [`.trunk/trunk.yaml`](.trunk/trunk.yaml) is pointing to your local
4. Add your linter definition to `plugin.yaml` (consult the docs for [custom linters] and [custom
parsers] to understand how it should be defined). Most linters in this repository are defined as
tools as well, so that they can be easily run manually from the command line.
5. Making sure the plugin in [`.trunk/trunk.yaml`](.trunk/trunk.yaml) is pointing to your local
repository, run `trunk check enable <my-linter>` to enable your linter, and run `trunk check` to
verify that the configuration is valid and that you get desired diagnostics. Running
`trunk check --verbose` can help provide greater insights when debugging.
5. Add a few simple test cases to `my_linter.test.ts` to exercise your linter and generate
snapshots. Refer to [Testing Guidelines](tests/readme.md) for more information on writing and
6. Add a few simple test cases to `my_linter.test.ts` to exercise your linter and generate
snapshots. Refer to [Testing Guidelines](tests/README.md) for more information on writing and
running tests.
6. Run `trunk check` to lint your changes.
7. Open a PR!
7. Run `trunk check` to lint your changes.
8. Open a PR!

[custom linters]: https://docs.trunk.io/docs/check-custom-linters
[custom parsers]: https://docs.trunk.io/docs/custom-parsers
Expand All @@ -105,7 +108,7 @@ To add a new action:
actions/
└─my-action/
│ plugin.yaml
└─readme.md
└─README.md
```

3. Add your action definition to `plugin.yaml` (consult the docs on [actions] to understand how it
Expand All @@ -116,17 +119,50 @@ To add a new action:
verify that the configuration is valid and that you get desired results. Running
`trunk actions history <my-action>` can help provide greater insights when debugging.
6. We have not yet defined a testing framework for plugin actions, but we are working to add one
soon! Please briefly document your action in its readme.md and in your PR.
soon! Please briefly document your action in its README.md and in your PR.
7. Run `trunk check` to lint your changes.
8. Open a PR!

[actions]: https://docs.trunk.io/docs/actions

## Tools

If the tool you intend to add functions primarily as a linter, please follow the instruction in
[linters](#linters). If it functions more as a standalone tool, please add it in the `tools/`
directory and follow the instructions below.

To add a new tool:

1. Run `trunk check` to start up Trunk in the background.
2. Create a directory inside `tools/` with the name of your new linter.
3. Inside this new directory, create the following structure. Most of these files will be
automatically created for you:

```text
tests/
└─my-tool/
│ plugin.yaml
│ my_tool.test.ts
└─README.md (optional)
```

4. Add your tool definition to `plugin.yaml` (consult the docs for
[custom tools](https://docs.trunk.io/tools/configuration#tool-definitions) to understand how it
should be defined).
5. Making sure the plugin in [`.trunk/trunk.yaml`](.trunk/trunk.yaml) is pointing to your local
repository, run `trunk tools enable <my-tool>` to enable your tool, and access its shim(s) to run
it from `.trunk/tools/<tool-name>`.
6. Add a `toolInstallTest` to `my_tool.test.ts` to verify your tool's installation. If neccessary,
use `toolTest` instead. Refer to [Testing Guidelines](tests/README.md) for more information on
writing and running tests.
7. Run `trunk check` to lint your changes.
8. Open a PR!

## Guidelines

Please follow the guidelines below when contributing:

- After defining a new linter or action, please add it to [`readme.md`](readme.md).
- After defining a new linter or action, please add it to [`README.md`](README.md).
- If you run into any problems while defining new linters or actions, feel free to reach out on our
[Slack](https://slack.trunk.io/). We are continuously working to improve the process of
integrating with trunk, and all feedback is appreciated!
Expand Down
26 changes: 16 additions & 10 deletions readme.md → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ plugins:
sources:
- id: trunk
uri: https://github.com/trunk-io/plugins
ref: v0.0.21
ref: v1.2.5
```
This repo is open to contributions! See our
[contribution guidelines](https://github.com/trunk-io/plugins/blob/main/contributing.md) and join
our [slack community][slack] for help.
our [slack community][slack] for help. **If you're adding new tools, please see our
[testing guide](tests/README.md) as well!**
### Supported Linters, Formatters, and Security Tools
Expand Down Expand Up @@ -130,7 +131,7 @@ trunk check enable {linter}
[perlcritic]: https://metacpan.org/pod/Perl::Critic
[perltidy]: https://metacpan.org/dist/Perl-Tidy/view/bin/perltidy
[pmd]: https://pmd.github.io/
[pragma-once]: linters/pragma-once/readme.md
[pragma-once]: linters/pragma-once/README.md
[prettier]: https://github.com/prettier/prettier#readme
[pre-commit-hooks]: https://pre-commit.com/hooks.html
[prisma]: https://github.com/prisma/prisma#readme
Expand Down Expand Up @@ -200,19 +201,24 @@ trunk actions enable {action}

| action | description |
| -------------------------------------------------------------------- | ---------------------------------------------------------- |
| [`buf-gen`](actions/buf/readme.md) | run `buf` on .proto file change |
| [`buf-gen`](actions/buf/README.md) | run `buf` on .proto file change |
| [`commitlint`](https://github.com/conventional-changelog/commitlint) | enforce conventional commit message for your local commits |
| [`go-mod-tidy`](actions/go-mod-tidy/readme.md) | automatically tidy go.mod file |
| [`go-mod-tidy-vendor`](actions/go-mod-tidy-vendor/readme.md) | automatically tidy and vendor go.mod file |
| [`git-blame-ignore-revs`](actions/git-blame-ignore-revs/readme.md) | automatically configure git to use .git-blame-ignore-revs |
| [`npm-check`](actions/npm-check/readme.md) | check whether NPM installation is up to date |
| [`yarn-check`](actions/yarn-check/readme.md) | check whether Yarn installation is up to date |
| [`go-mod-tidy`](actions/go-mod-tidy/README.md) | automatically tidy go.mod file |
| [`go-mod-tidy-vendor`](actions/go-mod-tidy-vendor/README.md) | automatically tidy and vendor go.mod file |
| [`git-blame-ignore-revs`](actions/git-blame-ignore-revs/README.md) | automatically configure git to use .git-blame-ignore-revs |
| [`npm-check`](actions/npm-check/README.md) | check whether NPM installation is up to date |
| [`yarn-check`](actions/yarn-check/README.md) | check whether Yarn installation is up to date |

### Supported Tools

This repository also defines configuration for Trunk Tools, which provides hermetic management of
different CLI tools. You can read more about it in our [docs](https://docs.trunk.io/tools).

### Mission

Our goal is to make engineering faster, more efficient and dare we say - more fun. This repository
will hopefully allow our community to share ideas on the best tools and best practices/workflows to
make everyone's job of building code a little bit easier, a little bit faster and maybe in the
make everyone's job of building code a little bit easier, a little bit faster, and maybe in the
process - a little bit more fun.

### Additional Reference
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions actions/buf/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ actions:
- id: buf-gen
display_name: Buf generate
description:
Run 'buf generate' anytime a .proto file changes. Must have a buf.work.yaml to work
properly.
Run 'buf generate' anytime a .proto file changes. Must have a buf.work.yaml to work properly
run: buf generate
triggers:
- files: ["**/*.proto", buf.gen.yaml, buf.work.yaml]
File renamed without changes.
2 changes: 2 additions & 0 deletions actions/commitlint/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ version: 0.1
actions:
definitions:
- id: commitlint
display_name: Commitlint
description: Enforce git commit message standards
runtime: node
packages_file: package.json
run: commitlint --edit ${1}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion actions/git-blame-ignore-revs/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ actions:
definitions:
- id: git-blame-ignore-revs
display_name: Auto-enable .git-blame-ignore-revs
description: Automatically configure git to use .git-blame-ignore-revs while the file exists.
description: Automatically configure git to use .git-blame-ignore-revs while the file exists
run: bash ${cwd}/update_config.sh
triggers:
- files: [.git-blame-ignore-revs]
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion actions/go-mod-tidy-vendor/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ actions:
definitions:
- id: go-mod-tidy-vendor
display_name: Go Mod Tidy & Vendor
description: Runs go mod tidy followed by go mod vendor.
description: Runs go mod tidy followed by go mod vendor
runtime: go
run: bash ${plugin}/actions/go-mod-tidy-vendor/go-mod-tidy-vendor.sh
triggers:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion actions/go-mod-tidy/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ actions:
definitions:
- id: go-mod-tidy
display_name: Go Mod Tidy
description: Runs go mod tidy when changes are detected to go.mod.
description: Runs go mod tidy when changes are detected to go.mod
runtime: go
run: go mod tidy
triggers:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion actions/hello-world/python/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ actions:
definitions:
- id: hello-world-python
display_name: Hello World
description: prints 'Hello World' to the terminal during pre-commit trigger
description: Prints 'Hello World' to the terminal during pre-commit trigger
runtime: python
packages_file: requirements.txt
run: python3 ${cwd}/hello # {cwd} resolves to current directory containing this plugin.yaml file
Expand Down
1 change: 1 addition & 0 deletions actions/npm-check-pre-push/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ actions:
definitions:
- id: npm-check-pre-push
display_name: NPM Check
description: Generate notifications if node_modules are out of date as a pre-push hook
runtime: node
packages_file: package.json
triggers:
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions actions/npm-check/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ actions:
definitions:
- id: npm-check
display_name: NPM Check
description: Generate notifications if node_modules are out of date
runtime: node
packages_file: package.json
triggers:
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions actions/yarn-check/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ actions:
definitions:
- id: yarn-check
display_name: Yarn Check
description: Generate notifications if node_modules are out of date
runtime: node
packages_file: package.json
triggers:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion linters/ansible-lint/ansible_lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const preCheck =

driver.moveFile(path.join(TEST_DATA, "jboss-standalone"), "jboss-standalone");

// See linters/ansible-lint/readme.md for details on non-FQCN support
// See linters/ansible-lint/README.md for details on non-FQCN support
if (!fqcn) {
const configFile = "jboss-standalone/demo-aws-launch.yml";
driver.writeFile(
Expand Down
6 changes: 3 additions & 3 deletions linters/autopep8/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ tools:
- name: autopep8
runtime: python
package: autopep8
extra_packages: [pycodestyle@2.10.0]
extra_packages: [pycodestyle]
shims: [autopep8]
known_good_version: 1.5.7
known_good_version: 2.0.4
lint:
definitions:
- name: autopep8
Expand All @@ -29,7 +29,7 @@ lint:
- setup.cfg
- tox.ini
issue_url_format: https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
known_good_version: 1.5.7
known_good_version: 2.0.4
version_command:
parse_regex: autopep8 ${semver}
run: autopep8 --version
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 6 additions & 1 deletion linters/trufflehog/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,16 @@ lint:
parse_regex: trufflehog ${semver}
run: trufflehog --version

# This action runs trufflehog-git as a pre-commit hook in order to make sure that secrets don't show up in individual commits,
# as opposed to the primary trufflehog linter integration, which is not git-aware. In order to run this action, you must also run
# 'trunk check enable trufflehog-git'
actions:
definitions:
- id: trufflehog-pre-commit
description: Don't allow secrets in commits (via Trufflehog)
display_name: Trufflehog Pre-Commit Hook
description:
Don't allow secrets in commits (via Trufflehog). Enable linter 'trufflehog-git' before
running
run: trunk check -t "git-commit" --upstream=HEAD --filter=trufflehog-git
interactive: optional
triggers:
Expand Down
2 changes: 1 addition & 1 deletion repo-tools/linter-test-helper/generate
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ INITIAL_TEST_CONTENTS = """import { linterCheckTest, linterFmtTest } from "tests
// - By default, linters and formatters will only run on files with syntax `<name>.in.<extension>`
// - You can customize test setup using the `preCheck` callback (see git_diff_check.test.ts and golangci_lint.test.ts)
// - You can specify additional customization using the `customLinterCheckTest and customLinterFmtTest` helpers
// - Additional information on test setup can be found in tests/readme.md
// - Additional information on test setup can be found in tests/README.md
//
// If you are unable to write a test for this linter, please document why in your PR, and add
// it to the list in tests/repo_tests/test_coverage_test.ts
Expand Down
File renamed without changes.
Loading

0 comments on commit 9717889

Please sign in to comment.