Skip to content

Commit

Permalink
New line linter (#502)
Browse files Browse the repository at this point in the history
Enables with:

```
enabled:
    - pre-commit-hooks@4.4.0:
        commands:
        - end-of-file-fixer
```
  • Loading branch information
pat-trunk-io authored Oct 4, 2023
1 parent f5dcd5b commit 6a633c3
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
14 changes: 14 additions & 0 deletions linters/pre-commit-hooks/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Pre-Commit-Hooks

The set of formatter and linters in this suite are disabled by default. Some of the
linters/formatters have different conflicting outputs.

To enabled, add the list of checks you want in your trunk.yaml as such:

```yaml
lint:
enabled:
- pre-commit-hooks@4.4.0:
commands:
- end-of-file-fixer
```
21 changes: 21 additions & 0 deletions linters/pre-commit-hooks/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 0.1
lint:
definitions:
- name: pre-commit-hooks
known_good_version: 4.4.0
runtime: python
package: pre-commit-hooks
suggest_if: never
environment:
- name: PATH
list: ["${env.PATH}"]
commands:
- name: end-of-file-fixer
enabled: false
output: rewrite
in_place: true
formatter: true
run: end-of-file-fixer ${target}
success_codes: [0, 1]
files:
- ALL
19 changes: 19 additions & 0 deletions linters/pre-commit-hooks/pre_commit_hooks.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { linterFmtTest, TestCallback } from "tests";

// Due to sqlfluff's fix subcommand being disabled by default, we need to manually enable it in the trunk.yaml.
const fmtCallbacks: TestCallback = (driver) => {
const trunkYamlPath = ".trunk/trunk.yaml";
const currentContents = driver.readFile(trunkYamlPath);
const sqlfluffRegex = /- pre-commit-hooks@(.+)\n/;
const newContents = currentContents.replace(
sqlfluffRegex,
"- pre-commit-hooks@$1:\n commands: [end-of-file-fixer]\n",
);
driver.writeFile(trunkYamlPath, newContents);
};

linterFmtTest({
linterName: "pre-commit-hooks",
namedTestPrefixes: ["end-of-file-fixer"],
preCheck: fmtCallbacks,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a file without a new line
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing formatter pre-commit-hooks test end-of-file-fixer 1`] = `
"This is a file without a new line
"
`;
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trunk check enable {linter}

| Technology | Linters |
| --------------- | -------------------------------------------------------------------------------------------------------------------- |
| All | [codespell], [cspell], [gitleaks], [git-diff-check] |
| All | [codespell], [cspell], [gitleaks], [git-diff-check], [pre-commit-hooks] |
| Ansible | [ansible-lint] |
| Apex | [pmd] |
| Bash | [shellcheck], [shfmt] |
Expand Down Expand Up @@ -132,6 +132,7 @@ trunk check enable {linter}
[pmd]: https://pmd.github.io/
[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
[pylint]: https://github.com/PyCQA/pylint#readme
[pyright]: https://github.com/microsoft/pyright
Expand Down

0 comments on commit 6a633c3

Please sign in to comment.