From d85efe7b11545ee852f556450265567985983482 Mon Sep 17 00:00:00 2001 From: Tyler Jang Date: Wed, 27 Mar 2024 17:40:45 -0700 Subject: [PATCH 1/3] start --- linters/ation/.ation | 1 + linters/ation/ation.py | 31 ++++++++++++++++++++ linters/ation/ation.test.ts | 3 ++ linters/ation/plugin.yaml | 21 +++++++++++++ linters/ation/test_data/ation_basic.fmt.shot | 24 +++++++++++++++ linters/ation/test_data/basic.in.py | 19 ++++++++++++ 6 files changed, 99 insertions(+) create mode 100644 linters/ation/.ation create mode 100644 linters/ation/ation.py create mode 100644 linters/ation/ation.test.ts create mode 100644 linters/ation/plugin.yaml create mode 100644 linters/ation/test_data/ation_basic.fmt.shot create mode 100644 linters/ation/test_data/basic.in.py diff --git a/linters/ation/.ation b/linters/ation/.ation new file mode 100644 index 000000000..f04c001f3 --- /dev/null +++ b/linters/ation/.ation @@ -0,0 +1 @@ +29 diff --git a/linters/ation/ation.py b/linters/ation/ation.py new file mode 100644 index 000000000..26101d6f6 --- /dev/null +++ b/linters/ation/ation.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +import os +import sys + +DEFAULT_LENGTH = 100 + + +def get_length(workspace): + config_file = workspace + "/.ation" + if not os.path.exists(config_file): + return DEFAULT_LENGTH + with open(config_file) as f: + return int(f.readline()) + + +if __name__ == "__main__": + line_length = DEFAULT_LENGTH + if len(sys.argv) > 1: + line_length = get_length(sys.argv[1]) + + out = "" + # TODO: TYLER REPLACE WITH READ + for line in sys.stdin: + replacement = line.replace("bad code", "good code")[:line_length] + if replacement[-1] == "\n": + out += replacement + else: + out += replacement + "\n" + + print(out[:-1]) diff --git a/linters/ation/ation.test.ts b/linters/ation/ation.test.ts new file mode 100644 index 000000000..715a11a62 --- /dev/null +++ b/linters/ation/ation.test.ts @@ -0,0 +1,3 @@ +import { linterFmtTest } from "tests"; + +linterFmtTest({ linterName: "ation" }); diff --git a/linters/ation/plugin.yaml b/linters/ation/plugin.yaml new file mode 100644 index 000000000..5fb76a50d --- /dev/null +++ b/linters/ation/plugin.yaml @@ -0,0 +1,21 @@ +version: 0.1 +lint: + definitions: + - name: ation + files: [ALL] + suggest_if: never + runtime: python + direct_configs: [.ation] + commands: + - name: format + output: rewrite + formatter: true + cache_results: true + stdin: true + run: python3 "${cwd}/ation.py" ${workspace} + success_codes: [0] + ignore: + - linters: [ation] + paths: + - "**/plugin.yaml" + - ".trunk/**/*" diff --git a/linters/ation/test_data/ation_basic.fmt.shot b/linters/ation/test_data/ation_basic.fmt.shot new file mode 100644 index 000000000..4b29d16d5 --- /dev/null +++ b/linters/ation/test_data/ation_basic.fmt.shot @@ -0,0 +1,24 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Testing formatter ation test basic 1`] = ` +"#!/usr/bin/env python3 + +GLOBAL_CONSTANT_128 = 10 * 12 + 8 + +# TODO: This is super clean. But have we considered what to do about roundoff error? +def add(a, b): + return a + b + +# This is good code +def fibonacci(n): + if n <= 0: + return 0 + elif n == 1: + return 1 + else: + return fibonacci(n-1) + fibonacci(n-2) + +if __name__ == "__main__": + print("Hello, World!") +" +`; diff --git a/linters/ation/test_data/basic.in.py b/linters/ation/test_data/basic.in.py new file mode 100644 index 000000000..24e9e01b2 --- /dev/null +++ b/linters/ation/test_data/basic.in.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 + +GLOBAL_CONSTANT_128 = 10 * 12 + 8 + +# TODO: This is super clean. But have we considered what to do about roundoff error? +def add(a, b): + return a + b + +# This is bad code +def fibonacci(n): + if n <= 0: + return 0 + elif n == 1: + return 1 + else: + return fibonacci(n-1) + fibonacci(n-2) + +if __name__ == "__main__": + print("Hello, World!") From 9bcafa3f4bf2a04649fc2ef5605dc3dd2332e846 Mon Sep 17 00:00:00 2001 From: Tyler Jang Date: Sun, 31 Mar 2024 20:36:54 -0700 Subject: [PATCH 2/3] done --- linters/ation/ation.py | 5 +---- linters/ation/plugin.yaml | 2 +- linters/ation/test_data/ation_basic.fmt.shot | 6 +++--- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/linters/ation/ation.py b/linters/ation/ation.py index 26101d6f6..4f764d6c0 100644 --- a/linters/ation/ation.py +++ b/linters/ation/ation.py @@ -15,12 +15,9 @@ def get_length(workspace): if __name__ == "__main__": - line_length = DEFAULT_LENGTH - if len(sys.argv) > 1: - line_length = get_length(sys.argv[1]) + line_length = get_length(os.getcwd()) out = "" - # TODO: TYLER REPLACE WITH READ for line in sys.stdin: replacement = line.replace("bad code", "good code")[:line_length] if replacement[-1] == "\n": diff --git a/linters/ation/plugin.yaml b/linters/ation/plugin.yaml index 5fb76a50d..a32c0e65a 100644 --- a/linters/ation/plugin.yaml +++ b/linters/ation/plugin.yaml @@ -18,4 +18,4 @@ lint: - linters: [ation] paths: - "**/plugin.yaml" - - ".trunk/**/*" + - .trunk/**/* diff --git a/linters/ation/test_data/ation_basic.fmt.shot b/linters/ation/test_data/ation_basic.fmt.shot index 4b29d16d5..b9cc69fd4 100644 --- a/linters/ation/test_data/ation_basic.fmt.shot +++ b/linters/ation/test_data/ation_basic.fmt.shot @@ -3,9 +3,9 @@ exports[`Testing formatter ation test basic 1`] = ` "#!/usr/bin/env python3 -GLOBAL_CONSTANT_128 = 10 * 12 + 8 +GLOBAL_CONSTANT_128 = 10 * 12 -# TODO: This is super clean. But have we considered what to do about roundoff error? +# TODO: This is super clean. def add(a, b): return a + b @@ -16,7 +16,7 @@ def fibonacci(n): elif n == 1: return 1 else: - return fibonacci(n-1) + fibonacci(n-2) + return fibonacci(n-1) if __name__ == "__main__": print("Hello, World!") From 625f97bd8fec7fd479694e010e5ddef4ab11547c Mon Sep 17 00:00:00 2001 From: Tyler Jang Date: Mon, 1 Apr 2024 10:16:11 -0700 Subject: [PATCH 3/3] polish --- .ation | 1 + linters/ation/README.md | 10 ++++++++++ linters/ation/plugin.yaml | 2 ++ linters/ation/test_data/basic.in.py | 8 ++++---- 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 .ation create mode 100644 linters/ation/README.md diff --git a/.ation b/.ation new file mode 100644 index 000000000..f04c001f3 --- /dev/null +++ b/.ation @@ -0,0 +1 @@ +29 diff --git a/linters/ation/README.md b/linters/ation/README.md new file mode 100644 index 000000000..a617576cd --- /dev/null +++ b/linters/ation/README.md @@ -0,0 +1,10 @@ +# Trunk Ation + +Bring the power of brevity straight to the command line! Avoid pesky code run-ons, incessant nesting, and +long line smells, all with the press of a button! + +Simply run the following to get started: + +```bash +trunk check --filter=ation +``` diff --git a/linters/ation/plugin.yaml b/linters/ation/plugin.yaml index a32c0e65a..6f748de06 100644 --- a/linters/ation/plugin.yaml +++ b/linters/ation/plugin.yaml @@ -19,3 +19,5 @@ lint: paths: - "**/plugin.yaml" - .trunk/**/* + enabled: + - ation diff --git a/linters/ation/test_data/basic.in.py b/linters/ation/test_data/basic.in.py index 24e9e01b2..00a0123fb 100644 --- a/linters/ation/test_data/basic.in.py +++ b/linters/ation/test_data/basic.in.py @@ -1,19 +1,19 @@ #!/usr/bin/env python3 -GLOBAL_CONSTANT_128 = 10 * 12 + 8 +GLOBAL_CONSTANT_128 = 10 * 12 -# TODO: This is super clean. But have we considered what to do about roundoff error? +# TODO: This is super clean. def add(a, b): return a + b -# This is bad code +# This is good code def fibonacci(n): if n <= 0: return 0 elif n == 1: return 1 else: - return fibonacci(n-1) + fibonacci(n-2) + return fibonacci(n-1) if __name__ == "__main__": print("Hello, World!") pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy