├── .github ├── PULL_REQUEST_TEMPLATE.md └── ISSUE_TEMPLATE │ └── bug_report.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── CODE_OF_CONDUCT.md └── rc └── jsts.kak /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Summary 2 | 3 | **Change:** 4 | What parts in the code changed and why. 5 | 6 | **Impact:** 7 | How do the described changes affect the behaviour of this project. 8 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Versions:** 24 | - kak-jsts: 25 | - Kakoune: 26 | - Shell: 27 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | We welcome any and all contributions through GitHub issues and pull requests. 2 | 3 | When contributing your first changes, please include an empty commit for 4 | copyright waiver using the following message (replace 'John Doe' with 5 | your name or nickname): 6 | 7 | John Doe Copyright Waiver 8 | 9 | I dedicate any and all copyright interest in this software to the 10 | public domain. I make this dedication for the benefit of the public at 11 | large and to the detriment of my heirs and successors. I intend this 12 | dedication to be an overt act of relinquishment in perpetuity of all 13 | present and future rights to this software under copyright law. 14 | 15 | The command to create an empty commit from the command-line is: 16 | 17 | git commit --allow-empty 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kak-jsts 2 | 3 | This project extends JavaScript and TypeScript support of [Kakoune](https://github.com/mawww/kakoune). 4 | It provides additional commands for linting and formatting of your files. 5 | All formatting and linting will be done according to your local project preferences, e.g. in `.eslintrc.js`. 6 | 7 | It does not provide additional language features. 8 | For that, check the [Kakoune Language Server Protocol Client](https://github.com/ul/kak-lsp) instead. 9 | 10 | ## Installation 11 | 12 | ### Prerequisites 13 | 14 | kak-jsts has two dependencies that must be available on your machine: 15 | 16 | 1. [eslint-formatter-kakoune](https://github.com/Delapouite/eslint-formatter-kakoune): 17 | * `npm i -g eslint-formatter-kakoune` 18 | 2. [jq](https://github.com/stedolan/jq) 19 | * Check installation instructions for your system (e.g. `brew install jq`). 20 | 21 | eslint-formatter-kakoune is required to enable Kakoune to interpret eslint's output. 22 | 23 | jq is required to parse eslint's output of the JSON formatter. 24 | 25 | ### With [plug.kak](https://github.com/andreyorst/plug.kak) 26 | 27 | Add this to your `kakrc`: 28 | 29 | ```sh 30 | plug "schemar/kak-jsts" 31 | ``` 32 | 33 | Restart Kakoune or re-source your `kakrc` and call the `plug-install` command. 34 | 35 | ### Without plugin manager 36 | 37 | Clone this repository to your `autoload` directory, or source the `rc/jsts.kak` file 38 | from your `kakrc`. 39 | 40 | ## Usage 41 | 42 | ### Formatting: 43 | 44 | kak-jsts provides three new commands: 45 | 46 | 1. `format-eslint` 47 | 2. `format-prettier` 48 | 3. `format-tslint` 49 | 50 | `format-eslint` and `format-pretter` will format your buffer without touching the disk. 51 | Due to a limitation in `tslint`, your buffer will be written, formatted on disk, and then reloaded. 52 | 53 | All formatting will be done according to your local project preferences, e.g. in `.eslintrc.js`. 54 | Kakoune must run in the root of the project for that to work. 55 | 56 | ### Other 57 | 58 | kak-jsts provides implementations for common kakoune commands: 59 | 60 | 1. `alt` 61 | 2. `lint` 62 | 63 | `alt` jumps to the alternate file (implementation ↔ test). 64 | Jumps between implementation und .test.(js|ts) or .spec.(js|ts) in the same directory. 65 | `alt` is an alias to `jsts-alternative-file`. 66 | 67 | Kak-jsts sets Kakoune's [lint](https://github.com/mawww/kakoune/blob/master/rc/tools/lint.kak) 68 | command to use eslint for JavaScript and TypeScript files. 69 | 70 | Linting will be done according to your local project preferences, e.g. in `.eslintrc.js`. 71 | Kakoune must run in the root of the project for that to work. 72 | 73 | ## Configuration Examples 74 | 75 | ```kak 76 | plug "schemar/kak-jsts" config %{ 77 | hook global WinSetOption filetype=(javascript|typescript) %{ 78 | map window user l -docstring 'lint' ': lint' 79 | map window user f -docstring 'format' ': format-eslint' 80 | 81 | # If you want to format before every write, you could do s.th. like this: 82 | hook window BufWritePre .* %{ 83 | evaluate-commands -no-hooks %{ 84 | format-eslint 85 | } 86 | } 87 | } 88 | } 89 | ``` 90 | 91 | If you use different formatters in different projects, you can source a local `kakrc` where you overwrite the formatting command, for example to be `format-prettier`. 92 | See [IDE on the Kakoune Wiki](https://github.com/mawww/kakoune/wiki/IDE#read-local-kakrc-file) for more info about that. 93 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at martinschenck@fastmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /rc/jsts.kak: -------------------------------------------------------------------------------- 1 | # ╭────────────────╥────────────╮ 2 | # │ Author: ║ File: │ 3 | # │ Martin Schenck ║ jsts.kak │ 4 | # ╞════════════════╩════════════╡ 5 | # │ JS/TS extension │ 6 | # ╞═════════════════════════════╡ 7 | # │ github.com/schemar/kak-jsts │ 8 | # ╰─────────────────────────────╯ 9 | 10 | # Initialization 11 | # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 12 | 13 | hook global WinSetOption filetype=(javascript|typescript) %{ 14 | # eslint as linter as per Kakoune Wiki. 15 | # Using `npm list` makes the command run on all systems regardless of the 16 | # location of global packages, but it is much slower. 17 | set window lintcmd 'run() { cat "$1" | npx eslint --format "$(npm list -g --depth=0 | head -1)/node_modules/eslint-formatter-kakoune/index.js" --stdin --stdin-filename "${kak_buffile}";} && run ' 18 | lint-show-diagnostics 19 | 20 | alias window alt jsts-alternative-file 21 | 22 | hook -once -always window WinSetOption filetype=.* %{ 23 | unalias window alt jsts-alternative-file 24 | } 25 | } 26 | 27 | # Commands 28 | # ‾‾‾‾‾‾‾‾ 29 | 30 | define-command format-eslint -docstring %{ 31 | Formats the current buffer using eslint. 32 | Respects your local project setup in eslintrc. 33 | } %{ 34 | evaluate-commands -draft -no-hooks -save-regs '|' %{ 35 | # Select all to format 36 | execute-keys '%' 37 | 38 | # eslint does a fix-dry-run with a json formatter which results in a JSON output to stdout that includes the fixed file. 39 | # jq then extracts the fixed file output from the JSON. -j returns the raw output without any escaping. 40 | set-register '|' %{ 41 | format_out="$(mktemp)" 42 | cat | \ 43 | npx eslint --format json \ 44 | --fix-dry-run \ 45 | --stdin \ 46 | --stdin-filename "$kak_buffile" | \ 47 | jq -j ".[].output" > "$format_out" 48 | if [ $? -eq 0 ] && [ $(wc -c < "$format_out") -gt 4 ]; then 49 | cat "$format_out" 50 | else 51 | printf 'eval -client %s %%{ fail eslint formatter returned an error %s }\n' "$kak_client" "$?" | kak -p "$kak_session" 52 | printf "%s" "$kak_quoted_selection" 53 | fi 54 | rm -f "$format_out" 55 | } 56 | 57 | # Replace all with content from register: 58 | execute-keys '|' 59 | } 60 | } 61 | 62 | define-command format-prettier -docstring %{ 63 | Formats the current buffer using prettier. 64 | Respects your local project setup in prettierrc. 65 | } %{ 66 | evaluate-commands -draft -no-hooks -save-regs '|' %{ 67 | # Select all to format 68 | execute-keys '%' 69 | 70 | # Run prettier on the selection from stdin 71 | set-register '|' %{ 72 | %sh{ 73 | echo "$kak_selection" | \ 74 | npx prettier --stdin-filepath $kak_buffile 75 | } 76 | } 77 | 78 | # Replace all with content from register: 79 | execute-keys '|' 80 | } 81 | } 82 | 83 | define-command format-tslint -docstring %{ 84 | Formats the current buffer using tslint. 85 | Writes the buffer to disk first, formats it there, and then reloads it. 86 | } %{ 87 | evaluate-commands -draft -no-hooks %{ 88 | # It is not possible to format with tslint using stdin. 89 | # Hence, it is required that the buffer be written to disk first, 90 | # formatted there, and then automatically reloaded. 91 | set-option window autoreload 'yes' 92 | write 93 | nop %sh{ 94 | npx tslint --fix "$kak_buffile" 95 | } 96 | hook -once window BufReload .* %{ 97 | unset-option window autoreload 98 | } 99 | } 100 | } 101 | 102 | define-command jsts-alternative-file -docstring %{ 103 | Jump to the alternate file (implementation ↔ test). 104 | Jumps between implementation und .test.(js|ts) or .spec.(js|ts) in the same directory. 105 | } %{ 106 | evaluate-commands %sh{ 107 | case $kak_buffile in 108 | *.test.ts) 109 | altfile=${kak_buffile%.test.ts}.ts 110 | test ! -f "$altfile" && echo "fail 'implementation file not found'" && exit 111 | ;; 112 | *.test.js) 113 | altfile=${kak_buffile%.test.js}.js 114 | test ! -f "$altfile" && echo "fail 'implementation file not found'" && exit 115 | ;; 116 | *.spec.ts) 117 | altfile=${kak_buffile%.spec.ts}.ts 118 | test ! -f "$altfile" && echo "fail 'implementation file not found'" && exit 119 | ;; 120 | *.spec.js) 121 | altfile=${kak_buffile%.spec.js}.js 122 | test ! -f "$altfile" && echo "fail 'implementation file not found'" && exit 123 | ;; 124 | *.ts) 125 | altfile=${kak_buffile%.ts}.test.ts 126 | test ! -f "$altfile" && \ 127 | # Check for spec if test doesn't exist: 128 | altfile=${kak_buffile%.ts}.spec.ts && \ 129 | test ! -f "$altfile" && \ 130 | echo "fail 'test file not found'" && \ 131 | exit 132 | ;; 133 | *.js) 134 | altfile=${kak_buffile%.js}.test.js 135 | test ! -f "$altfile" && \ 136 | # Check for spec if test doesn't exist: 137 | altfile=${kak_buffile%.js}.spec.js && \ 138 | test ! -f "$altfile" && \ 139 | echo "fail 'test file not found'" && \ 140 | exit 141 | ;; 142 | *) 143 | echo "fail 'alternative file not found'" && exit 144 | ;; 145 | esac 146 | printf "edit '%s'" "${altfile}" 147 | } 148 | } 149 | --------------------------------------------------------------------------------