diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..dc43a73 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,97 @@ +name: Continuous Integration + +on: + push: + branches: + - main + - next + pull_request: + branches: + - main + - next + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + lint: + name: Lint Lua with Luacheck + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Luacheck linter + uses: lunarmodules/luacheck@v1 + + format: + name: Check Formatting with StyLua + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + - uses: JohnnyMorganz/stylua-action@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + version: v0.20.0 # NOTE: we recommend pinning to a specific version in case of formatting changes + # CLI arguments + args: --check lua/ + + test: + name: Run Neovim Tests + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + neovim_version: + - nightly + - stable + - v0.10.2 + - v0.9.5 + - v0.8.3 + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - uses: rhysd/action-setup-vim@v1 + with: + neovim: true + version: ${{ matrix.neovim_version}} + + - uses: extractions/setup-just@v1 + with: + just-version: 1.36.0 # optional semver specification, otherwise latest + + - name: Run tests + run: just test + release: + needs: [lint, format, test] + runs-on: ubuntu-latest + permissions: + contents: write + issues: write + pull-requests: write + steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + + - name: Checkout repository + uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Semantic Release + uses: cycjimmy/semantic-release-action@b1b432f13acb7768e0c8efdec416d363a57546f2 # v4.1.1 + id: semantic + with: + semantic_version: 24.0.0 + extra_plugins: | + @semantic-release/exec@6 + @semantic-release/git@10 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/scorecard.yaml b/.github/workflows/scorecard.yaml new file mode 100644 index 0000000..b6f2b15 --- /dev/null +++ b/.github/workflows/scorecard.yaml @@ -0,0 +1,42 @@ +name: Scorecard supply-chain security +on: + branch_protection_rule: + schedule: + - cron: "30 1 * * 4" + push: + branches: ["main"] + +permissions: read-all + +jobs: + analysis: + name: Scorecard analysis + runs-on: ubuntu-latest + permissions: + security-events: write + id-token: write + + steps: + - name: "Checkout code" + uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + with: + persist-credentials: false + + - name: "Run analysis" + uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # v2.4.0 + with: + results_file: results.sarif + results_format: sarif + publish_results: true + + - name: "Upload artifact" + uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.pre.node20 + with: + name: SARIF file + path: results.sarif + retention-days: 5 + + - name: "Upload to code-scanning" + uses: github/codeql-action/upload-sarif@f779452ac5af1c261dce0346a8f964149f49322b # v3 + with: + sarif_file: results.sarif diff --git a/.gitignore b/.gitignore index 50a5c31..4933f7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -/plugin/reload.vim \ No newline at end of file +!scripts/ +/plugin/reload.vim +deps/ +.ci diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..084dc49 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,4 @@ +globals = { "vim", "MiniTest" } +max_line_length = false + +exclude_files = { "deps" } diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000..85eb8d6 --- /dev/null +++ b/.luarc.json @@ -0,0 +1,11 @@ +{ + "diagnostics.globals": [ + "vim", + "MiniTest" + ], + "runtime.version": "LuaJIT", + "workspace.library": [ + "/usr/local/share/nvim/runtime/lua", + ".ci/neovim/share/nvim/runtime/lua" + ] +} diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 0000000..2510c11 --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,16 @@ +{ + "MD003": { + "style": "atx" + }, + "MD007": { + "indent": 2 + }, + "MD013": false, + "MD024": false, + "MD033": false, + "MD041": false, + "default": true, + "link-fragments": false, + "no-hard-tabs": true, + "whitespace": false +} diff --git a/.markdownlintignore b/.markdownlintignore new file mode 100644 index 0000000..e19d7c0 --- /dev/null +++ b/.markdownlintignore @@ -0,0 +1,4 @@ +^LICENSE +.github/**/* +meta/LICENSE-HEADER +guide/src/SUMMARY.md diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..28d9a01 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,125 @@ +# SPDX-FileCopyrightText: 2024 Ali Sajid Imami +# +# SPDX-License-Identifier: MIT + +default_stages: + - pre-commit + - commit-msg + - pre-push +repos: + - repo: https://github.com/commitizen-tools/commitizen + rev: v3.29.1 + hooks: + - id: commitizen + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-json + - id: no-commit-to-branch + args: + - --branch + - main + - --branch + - next + - id: check-merge-conflict + - id: check-toml + - id: check-xml + - id: check-yaml + - id: end-of-file-fixer + - id: mixed-line-ending + args: + - --fix=no + - id: pretty-format-json + args: + - --indent=4 + - --autofix + - id: trailing-whitespace + args: + - --markdown-linebreak-ext=md + - id: check-added-large-files + + - repo: https://github.com/compilerla/conventional-pre-commit + rev: v3.4.0 + hooks: + - id: conventional-pre-commit + args: + - build + - chore + - ci + - docs + - feat + - fix + - perf + - refactor + - revert + - style + - test + - bump + stages: + - commit-msg + + - repo: https://github.com/Lucas-C/pre-commit-hooks + rev: v1.5.5 + hooks: + - id: forbid-crlf + - id: remove-crlf + - id: forbid-tabs + - id: remove-tabs + + - repo: https://github.com/adrienverge/yamllint + rev: v1.35.1 + hooks: + - id: yamllint + args: + - --config=$(pwd)/.yamllint.yml + stages: + - commit-msg + + - repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.42.0 + hooks: + - id: markdownlint + args: + - --ignore + - CHANGELOG.md + + - repo: https://github.com/Yelp/detect-secrets + rev: v1.5.0 + hooks: + - id: detect-secrets + args: + - '--baseline' + - '.secrets.baseline' + exclude: 'pnpm-lock.yaml' + + - repo: https://github.com/sirosen/texthooks + rev: 0.6.7 + hooks: + - id: fix-smartquotes + - id: fix-ligatures + - id: forbid-bidi-controls + + - repo: https://github.com/zricethezav/gitleaks + rev: v8.21.0 + hooks: + - id: gitleaks + + - repo: https://github.com/fsfe/reuse-tool + rev: 'v4.0.3' + hooks: + - id: reuse + + - repo: https://github.com/renovatebot/pre-commit-hooks + rev: 38.124.0 + hooks: + - id: renovate-config-validator + + - repo: https://github.com/Calinou/pre-commit-luacheck + rev: v1.0.0 + hooks: + - id: luacheck + - repo: https://github.com/JohnnyMorganz/StyLua + rev: v0.20.0 + hooks: + - id: stylua # or stylua-system / stylua-github diff --git a/.secrets.baseline b/.secrets.baseline new file mode 100644 index 0000000..fa2cd97 --- /dev/null +++ b/.secrets.baseline @@ -0,0 +1,127 @@ +{ + "version": "1.5.0", + "plugins_used": [ + { + "name": "ArtifactoryDetector" + }, + { + "name": "AWSKeyDetector" + }, + { + "name": "AzureStorageKeyDetector" + }, + { + "name": "Base64HighEntropyString", + "limit": 4.5 + }, + { + "name": "BasicAuthDetector" + }, + { + "name": "CloudantDetector" + }, + { + "name": "DiscordBotTokenDetector" + }, + { + "name": "GitHubTokenDetector" + }, + { + "name": "GitLabTokenDetector" + }, + { + "name": "HexHighEntropyString", + "limit": 3.0 + }, + { + "name": "IbmCloudIamDetector" + }, + { + "name": "IbmCosHmacDetector" + }, + { + "name": "IPPublicDetector" + }, + { + "name": "JwtTokenDetector" + }, + { + "name": "KeywordDetector", + "keyword_exclude": "" + }, + { + "name": "MailchimpDetector" + }, + { + "name": "NpmDetector" + }, + { + "name": "OpenAIDetector" + }, + { + "name": "PrivateKeyDetector" + }, + { + "name": "PypiTokenDetector" + }, + { + "name": "SendGridDetector" + }, + { + "name": "SlackDetector" + }, + { + "name": "SoftlayerDetector" + }, + { + "name": "SquareOAuthDetector" + }, + { + "name": "StripeDetector" + }, + { + "name": "TelegramBotTokenDetector" + }, + { + "name": "TwilioKeyDetector" + } + ], + "filters_used": [ + { + "path": "detect_secrets.filters.allowlist.is_line_allowlisted" + }, + { + "path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies", + "min_level": 2 + }, + { + "path": "detect_secrets.filters.heuristic.is_indirect_reference" + }, + { + "path": "detect_secrets.filters.heuristic.is_likely_id_string" + }, + { + "path": "detect_secrets.filters.heuristic.is_lock_file" + }, + { + "path": "detect_secrets.filters.heuristic.is_not_alphanumeric_string" + }, + { + "path": "detect_secrets.filters.heuristic.is_potential_uuid" + }, + { + "path": "detect_secrets.filters.heuristic.is_prefixed_with_dollar_sign" + }, + { + "path": "detect_secrets.filters.heuristic.is_sequential_string" + }, + { + "path": "detect_secrets.filters.heuristic.is_swagger_file" + }, + { + "path": "detect_secrets.filters.heuristic.is_templated_secret" + } + ], + "results": {}, + "generated_at": "2024-10-14T20:22:13Z" +} diff --git a/.yamlfmt b/.yamlfmt new file mode 100644 index 0000000..e493519 --- /dev/null +++ b/.yamlfmt @@ -0,0 +1,16 @@ +--- +# SPDX-FileCopyrightText: 2022 - 2024 Ali Sajid Imami +# +# SPDX-License-Identifier: CC0-1.0 +line_ending: "lf" +doublestar: true +include: + - .github/**/*.yml + - .pre-commit-config.yaml + - .yamlfmt +formatter: + type: basic + include_document_start: true + line_ending: "lf" + max_line_length: 150 + indent: 4 diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 0000000..db407d8 --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,17 @@ +--- +# SPDX-FileCopyrightText: 2022 - 2024 Ali Sajid Imami +# +# SPDX-License-Identifier: CC0-1.0 +extends: default +rules: + # 80 chars should be enough, but don't fail if a line is longer + line-length: + max: 150 + level: warning + truthy: + check-keys: false + indentation: + spaces: 4 + indent-sequences: true + comments: + min-spaces-from-content: 1 diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..4294377 --- /dev/null +++ b/Justfile @@ -0,0 +1,96 @@ +# SPDX-FileCopyrightText: 2024 Ali Sajid Imami +# +# SPDX-License-Identifier: MIT + +set unstable + +_default: + just --list + +# Do a full run of linting, testing, and documentation generation. +all: documentation lint luals test + +# Run all the test files. +test: deps + nvim --version | head -n 1 && echo '' + nvim --headless --noplugin -u ./scripts/minimal_init.lua \ + -c "lua require('mini.test').setup()" \ + -c "lua MiniTest.run({ execute = { reporter = MiniTest.gen_reporter.stdout({ group_depth = 2 }) } })" + +# Install `mini.nvim`, used for both the tests and documentation. +[script("bash")] +deps: + set -euxo pipefail + if [ -d deps/mini.nvim ]; then + cd deps/mini.nvim && git pull + else + mkdir -p deps + git clone --depth 1 https://github.com/echasnovski/mini.nvim deps/mini.nvim + fi + +# Install deps before running tests, useful for the CI. +test-ci: deps test + +# Generates the documentation. +documentation: + nvim --headless --noplugin -u ./scripts/minimal_init.lua -c "lua require('mini.doc').generate()" -c "qa!" + +# installs deps before running the documentation generation, useful for the CI. +documentation-ci: deps documentation + +# Perform a lint check and fix issue if possible, following the config in `stylua.toml`. +lint: + stylua . -g '*.lua' -g '!deps/' -g '!nightly/' + luacheck plugin/ lua/ + +# Set the CI up for linting +[script("bash")] +luals-ci: + set -euxo pipefail + rm -rf .ci/lua-ls/log + lua-language-server --configpath .luarc.json --logpath .ci/lua-ls/log --check . + if [ -f .ci/lua-ls/log/check.json ]; then + if ! jq -e '. == []' .ci/lua-ls/log/check.json > /dev/null; then + cat .ci/lua-ls/log/check.json 2>/dev/null + exit 1 + fi + fi + +# Download and install lua lua-language-server for CI +luals: + mkdir -p .ci/lua-ls + curl -sL "https://github.com/LuaLS/lua-language-server/releases/download/3.7.4/lua-language-server-3.7.4-darwin-x64.tar.gz" | tar xzf - -C "${PWD}/.ci/lua-ls" + just luals-ci + +_download-neovim version: + # Download and use Neovim specified version + mkdir -p ./nvim/${version} + curl -L https://github.com/neovim/neovim/releases/download/${version}/nvim-macos.tar.gz -o ./nvim/${version}/nvim-macos.tar.gz + tar xzf ./nvim/${version}/nvim-macos.tar.gz -C ./nvim/${version} --strip-components=1 + +_test-version version: + just _download-neovim ${version} + ./nvim/${version}/bin/nvim --version + PATH=./nvim/${version}/bin:$PATH just test + +version := "placeholder" + +# Test against the nightly version of Neovim +test-nightly: + just _test-version nightly + +# Test against the stable version of Neovim +test-stable: + just _test-version stable + +# Test against the v0.8.3 version of Neovim +test-0-8-3: + just _test-version v0.8.3 + +# Test against the v0.9.5 version of Neovim +test-0-9-5: + just _test-version v0.9.5 + +# Test against the v0.8.3 version of Neovim +test-0-10-2: + just _test-version v0.10.2 diff --git a/LICENSES/CC0-1.0.txt b/LICENSES/CC0-1.0.txt new file mode 100644 index 0000000..0e259d4 --- /dev/null +++ b/LICENSES/CC0-1.0.txt @@ -0,0 +1,121 @@ +Creative Commons Legal Code + +CC0 1.0 Universal + + CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE + LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN + ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS + INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES + REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS + PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM + THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED + HEREUNDER. + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator +and subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for +the purpose of contributing to a commons of creative, cultural and +scientific works ("Commons") that the public can reliably and without fear +of later claims of infringement build upon, modify, incorporate in other +works, reuse and redistribute as freely as possible in any form whatsoever +and for any purposes, including without limitation commercial purposes. +These owners may contribute to the Commons to promote the ideal of a free +culture and the further production of creative, cultural and scientific +works, or to gain reputation or greater distribution for their Work in +part through the use and efforts of others. + +For these and/or other purposes and motivations, and without any +expectation of additional consideration or compensation, the person +associating CC0 with a Work (the "Affirmer"), to the extent that he or she +is an owner of Copyright and Related Rights in the Work, voluntarily +elects to apply CC0 to the Work and publicly distribute the Work under its +terms, with knowledge of his or her Copyright and Related Rights in the +Work and the meaning and intended legal effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not +limited to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, + communicate, and translate a Work; + ii. moral rights retained by the original author(s) and/or performer(s); +iii. publicity and privacy rights pertaining to a person's image or + likeness depicted in a Work; + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + v. rights protecting the extraction, dissemination, use and reuse of data + in a Work; + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation + thereof, including any amended or successor version of such + directive); and +vii. other similar, equivalent or corresponding rights throughout the + world based on applicable law or treaty, and any national + implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention +of, applicable law, Affirmer hereby overtly, fully, permanently, +irrevocably and unconditionally waives, abandons, and surrenders all of +Affirmer's Copyright and Related Rights and associated claims and causes +of action, whether now known or unknown (including existing as well as +future claims and causes of action), in the Work (i) in all territories +worldwide, (ii) for the maximum duration provided by applicable law or +treaty (including future time extensions), (iii) in any current or future +medium and for any number of copies, and (iv) for any purpose whatsoever, +including without limitation commercial, advertising or promotional +purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each +member of the public at large and to the detriment of Affirmer's heirs and +successors, fully intending that such Waiver shall not be subject to +revocation, rescission, cancellation, termination, or any other legal or +equitable action to disrupt the quiet enjoyment of the Work by the public +as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason +be judged legally invalid or ineffective under applicable law, then the +Waiver shall be preserved to the maximum extent permitted taking into +account Affirmer's express Statement of Purpose. In addition, to the +extent the Waiver is so judged Affirmer hereby grants to each affected +person a royalty-free, non transferable, non sublicensable, non exclusive, +irrevocable and unconditional license to exercise Affirmer's Copyright and +Related Rights in the Work (i) in all territories worldwide, (ii) for the +maximum duration provided by applicable law or treaty (including future +time extensions), (iii) in any current or future medium and for any number +of copies, and (iv) for any purpose whatsoever, including without +limitation commercial, advertising or promotional purposes (the +"License"). The License shall be deemed effective as of the date CC0 was +applied by Affirmer to the Work. Should any part of the License for any +reason be judged legally invalid or ineffective under applicable law, such +partial invalidity or ineffectiveness shall not invalidate the remainder +of the License, and in such case Affirmer hereby affirms that he or she +will not (i) exercise any of his or her remaining Copyright and Related +Rights in the Work or (ii) assert any associated claims and causes of +action with respect to the Work, in either case contrary to Affirmer's +express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + b. Affirmer offers the Work as-is and makes no representations or + warranties of any kind concerning the Work, express, implied, + statutory or otherwise, including without limitation warranties of + title, merchantability, fitness for a particular purpose, non + infringement, or the absence of latent or other defects, accuracy, or + the present or absence of errors, whether or not discoverable, all to + the greatest extent permissible under applicable law. + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without + limitation any person's Copyright and Related Rights in the Work. + Further, Affirmer disclaims responsibility for obtaining any necessary + consents, permissions or other rights required for any use of the + Work. + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to + this CC0 or use of the Work. diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt new file mode 100644 index 0000000..2071b23 --- /dev/null +++ b/LICENSES/MIT.txt @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 276a4c5..f5e5302 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,138 @@ -## neovim-vivify-markdown -This is the README for neovim-vivify-markdown \ No newline at end of file + + +

+

my-awesome-plugin.nvim

+

+ +

+ > A catch phrase that describes your plugin. +

+ +
+ > Drag your video (<10MB) here to host it for free on GitHub. +
+ +
+ +> Videos don't work on GitHub mobile, so a GIF alternative can help users. + +_[GIF version of the showcase video for mobile users](SHOWCASE_GIF_LINK)_ + +
+ +## ⚡️ Features + +> Write short sentences describing your plugin features + +- FEATURE 1 +- FEATURE .. +- FEATURE N + +## 📋 Installation + +
+ + + + + + + + + + + + + + + + + + + + + +
Package managerSnippet
+ +[wbthomason/packer.nvim](https://github.com/wbthomason/packer.nvim) + + + +```lua +-- stable version +use {"my-awesome-plugin.nvim", tag = "*" } +-- dev version +use {"my-awesome-plugin.nvim"} +``` + +
+ +[junegunn/vim-plug](https://github.com/junegunn/vim-plug) + + + +```lua +-- stable version +Plug "my-awesome-plugin.nvim", { "tag": "*" } +-- dev version +Plug "my-awesome-plugin.nvim" +``` + +
+ +[folke/lazy.nvim](https://github.com/folke/lazy.nvim) + + + +```lua +-- stable version +require("lazy").setup({{"my-awesome-plugin.nvim", version = "*"}}) +-- dev version +require("lazy").setup({"my-awesome-plugin.nvim"}) +``` + +
+
+ +## ☄ Getting started + +> Describe how to use the plugin the simplest way + +## ⚙ Configuration + +> The configuration list sometimes become cumbersome, making it folded by default reduce the noise of the README file. + +
+Click to unfold the full list of options with their default values + +> **Note**: The options are also available in Neovim by calling `:h my-awesome-plugin.options` + +```lua +require("my-awesome-plugin").setup({ + -- you can copy the full list from lua/my-awesome-plugin/config.lua +}) +``` + +
+ +## 🧰 Commands + +| Command | Description | +|-------------|----------------------------| +| `:Toggle` | Enables the plugin. | + +## ⌨ Contributing + +PRs and issues are always welcome. Make sure to provide as much context as possible when opening one. + +## 🗞 Wiki + +You can find guides and showcase of the plugin on [the Wiki](https://github.com/aimami/my-awesome-plugin.nvim/wiki) + +## 🎭 Motivations + +> If alternatives of your plugin exist, you can provide some pros/cons of using yours over the others. diff --git a/REUSE.toml b/REUSE.toml new file mode 100644 index 0000000..4dfd442 --- /dev/null +++ b/REUSE.toml @@ -0,0 +1,63 @@ +# SPDX-FileCopyrightText: 2022 - 2024 Ali Sajid Imami +# +# SPDX-License-Identifier: CC0-1.0 + +version = 1 + +[[annotations]] +path = [ + ".gitleaksignore", + ".gitignore", + ".secrets.baseline", + ".markdownlintignore", +] +precedence = "override" +SPDX-FileCopyrightText = "2024 Ali Sajid Imami" +SPDX-License-Identifier = "CC0-1.0" + +[[annotations]] +path = [ + "renovate.json", + ".markdownlint.json", + ".vale.ini", + ".releaserc.yml", + ".cspell.json", + ".jscpd.json", + ".mega-linter.yml", + ".luacheckrc", + ".luarc.json" +] +precedence = "override" +SPDX-FileCopyrightText = "2024 Ali Sajid Imami" +SPDX-License-Identifier = "CC0-1.0" + +[[annotations]] +path = ".github/workflows/*" +precedence = "override" +SPDX-FileCopyrightText = "2024 Ali Sajid Imami" +SPDX-License-Identifier = "CC0-1.0" + +[[annotations]] +path = [ + ".github/ISSUE_TEMPLATE/*", + ".github/PULL_REQUEST_TEMPLATE.md" +] +precedence = "override" +SPDX-FileCopyrightText = "2024 Ali Sajid Imami" +SPDX-License-Identifier = "CC0-1.0" + +[[annotations]] +path = [ + "CHANGELOG.md", +] +precedence = "override" +SPDX-FileCopyrightText = "2024 Ali Sajid Imami" +SPDX-License-Identifier = "MIT" + +[[annotations]] +path = [ + "meta/vale-styles/config/vocabularies/Custom/accept.txt" +] +precedence = "override" +SPDX-FileCopyrightText = "2024 Ali Sajid Imami" +SPDX-License-Identifier = "CC0-1.0" diff --git a/doc/neovim-vivify-markdown.txt b/doc/neovim-vivify-markdown.txt deleted file mode 100644 index e69de29..0000000 diff --git a/doc/tags b/doc/tags deleted file mode 100644 index e69de29..0000000 diff --git a/lua/neovim-vivify-markdown/config.lua b/lua/neovim-vivify-markdown/config.lua index e69de29..209fcdc 100644 --- a/lua/neovim-vivify-markdown/config.lua +++ b/lua/neovim-vivify-markdown/config.lua @@ -0,0 +1,52 @@ +-- SPDX-FileCopyrightText: 2024 Ali Sajid Imami +-- +-- SPDX-License-Identifier: MIT +local log = require("neovim-vivify-markdown.util.log") + +local NeovimVivifyMarkdown = {} + +--- NeovimVivifyMarkdown configuration with its default values. +--- +---@type table +--- Default values: +---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section) +NeovimVivifyMarkdown.options = { + -- Prints useful logs about what event are triggered, and reasons actions are executed. + debug = false, +} + +---@private +local defaults = vim.deepcopy(NeovimVivifyMarkdown.options) + +--- Defaults NeovimVivifyMarkdown options by merging user provided options with the default plugin values. +--- +---@param options table Module config table. See |NeovimVivifyMarkdown.options|. +--- +---@private +function NeovimVivifyMarkdown.defaults(options) + NeovimVivifyMarkdown.options = + vim.deepcopy(vim.tbl_deep_extend("keep", options or {}, defaults or {})) + + -- let your user know that they provided a wrong value, this is reported when your plugin is executed. + assert( + type(NeovimVivifyMarkdown.options.debug) == "boolean", + "`debug` must be a boolean (`true` or `false`)." + ) + + return NeovimVivifyMarkdown.options +end + +--- Define your setup. +--- +---@param options table Module config table. See |NeovimVivifyMarkdown.options|. +--- +---@usage `require("").setup()` (add `{}` with your |NeovimVivifyMarkdown.options| table) +function NeovimVivifyMarkdown.setup(options) + NeovimVivifyMarkdown.options = NeovimVivifyMarkdown.defaults(options or {}) + + log.warn_deprecation(NeovimVivifyMarkdown.options) + + return NeovimVivifyMarkdown.options +end + +return NeovimVivifyMarkdown diff --git a/lua/neovim-vivify-markdown/init.lua b/lua/neovim-vivify-markdown/init.lua index ea88d5a..31bcf28 100644 --- a/lua/neovim-vivify-markdown/init.lua +++ b/lua/neovim-vivify-markdown/init.lua @@ -1,5 +1,42 @@ +-- SPDX-FileCopyrightText: 2024 Ali Sajid Imami +-- +-- SPDX-License-Identifier: MIT + --[[ this module exposes the interface of lua functions: define here the lua functions that activate the plugin ]] local main = require("neovim-vivify-markdown.main") local config = require("neovim-vivify-markdown.config") +local NeovimVivifyMarkdown = {} + +--- Toggle the plugin by calling the `enable`/`disable` methods respectively. +function NeovimVivifyMarkdown.toggle() + if _G.NeovimVivifyMarkdown.config == nil then + _G.NeovimVivifyMarkdown.config = config.options + end + + main.toggle("public_api_toggle") +end + +--- Initializes the plugin, sets event listeners and internal state. +function NeovimVivifyMarkdown.enable(scope) + if _G.NeovimVivifyMarkdown.config == nil then + _G.NeovimVivifyMarkdown.config = config.options + end + + main.toggle(scope or "public_api_enable") +end + +--- Disables the plugin, clear highlight groups and autocmds, closes side buffers and resets the internal state. +function NeovimVivifyMarkdown.disable() + main.toggle("public_api_disable") +end + +-- setup NeovimVivifyMarkdown options and merge them with user provided ones. +function NeovimVivifyMarkdown.setup(opts) + _G.NeovimVivifyMarkdown.config = config.setup(opts) +end + +_G.NeovimVivifyMarkdown = NeovimVivifyMarkdown + +return _G.NeovimVivifyMarkdown diff --git a/lua/neovim-vivify-markdown/main.lua b/lua/neovim-vivify-markdown/main.lua index ffd0612..d9500ed 100644 --- a/lua/neovim-vivify-markdown/main.lua +++ b/lua/neovim-vivify-markdown/main.lua @@ -1 +1,61 @@ -local config = require("neovim-vivify-markdown.config") \ No newline at end of file +-- SPDX-FileCopyrightText: 2024 Ali Sajid Imami +-- +-- SPDX-License-Identifier: MIT + +local log = require("neovim-vivify-markdown.util.log") +local state = require("neovim-vivify-markdown.state") + +-- internal methods +local main = {} + +-- Toggle the plugin by calling the `enable`/`disable` methods respectively. +-- +---@param scope string: internal identifier for logging purposes. +---@private +function main.toggle(scope) + if state.get_enabled(state) then + log.debug(scope, "neovim-vivify-markdown is now disabled!") + + return main.disable(scope) + end + + log.debug(scope, "neovim-vivify-markdown is now enabled!") + + main.enable(scope) +end + +--- Initializes the plugin, sets event listeners and internal state. +--- +--- @param scope string: internal identifier for logging purposes. +---@private +function main.enable(scope) + if state.get_enabled(state) then + log.debug(scope, "neovim-vivify-markdown is already enabled") + + return + end + + state.set_enabled(state) + + -- saves the state globally to `_G.NeovimVivifyMarkdown.state` + state.save(state) +end + +--- Disables the plugin for the given tab, clear highlight groups and autocmds, closes side buffers and resets the internal state. +--- +--- @param scope string: internal identifier for logging purposes. +---@private +function main.disable(scope) + if not state.get_enabled(state) then + log.debug(scope, "neovim-vivify-markdown is already disabled") + + return + end + + state.set_disabled(state) + + -- saves the state globally to `_G.NeovimVivifyMarkdown.state` + state.save(state) +end + +return main diff --git a/lua/neovim-vivify-markdown/state.lua b/lua/neovim-vivify-markdown/state.lua new file mode 100644 index 0000000..2c1454e --- /dev/null +++ b/lua/neovim-vivify-markdown/state.lua @@ -0,0 +1,47 @@ +-- SPDX-FileCopyrightText: 2024 Ali Sajid Imami +-- +-- SPDX-License-Identifier: MIT + +local log = require("neovim-vivify-markdown.util.log") + +local state = { enabled = false } + +---Sets the state to its original value. +--- +---@private +function state:init() + self.enabled = false +end + +---Saves the state in the global _G.NeovimVivifyMarkdown.state object. +--- +---@private +function state:save() + log.debug("state.save", "saving state globally to _G.NeovimVivifyMarkdown.state") + + _G.NeovimVivifyMarkdown.state = self +end + +--- Sets the global state as enabled. +--- +---@private +function state:set_enabled() + self.enabled = true +end + +--- Sets the global state as disabled. +--- +---@private +function state:set_disabled() + self.enabled = false +end + +---Whether the NeovimVivifyMarkdown is enabled or not. +--- +---@return boolean: the `enabled` state value. +---@private +function state:get_enabled() + return self.enabled +end + +return state diff --git a/lua/neovim-vivify-markdown/util/log.lua b/lua/neovim-vivify-markdown/util/log.lua new file mode 100644 index 0000000..27e1b71 --- /dev/null +++ b/lua/neovim-vivify-markdown/util/log.lua @@ -0,0 +1,94 @@ +-- SPDX-FileCopyrightText: 2024 Ali Sajid Imami +-- +-- SPDX-License-Identifier: MIT +local log = {} + +local longest_scope = 15 + +--- prints only if debug is true. +--- +---@param scope string: the scope from where this function is called. +---@param str string: the formatted string. +---@param ... any: the arguments of the formatted string. +---@private +function log.debug(scope, str, ...) + return log.notify(scope, vim.log.levels.DEBUG, false, str, ...) +end + +--- prints only if debug is true. +--- +---@param scope string: the scope from where this function is called. +---@param level string: the log level of vim.notify. +---@param verbose boolean: when false, only prints when config.debug is true. +---@param str string: the formatted string. +---@param ... any: the arguments of the formatted string. +---@private +function log.notify(scope, level, verbose, str, ...) + if + not verbose + and _G.NeovimVivifyMarkdown.config ~= nil + and not _G.NeovimVivifyMarkdown.config.debug + then + return + end + + if string.len(scope) > longest_scope then + longest_scope = string.len(scope) + end + + for i = longest_scope, string.len(scope), -1 do + if i < string.len(scope) then + scope = string.format("%s ", scope) + else + scope = string.format("%s", scope) + end + end + + vim.notify( + string.format("[neovim-vivify-markdown.nvim@%s] %s", scope, string.format(str, ...)), + level, + { title = "neovim-vivify-markdown.nvim" } + ) +end + +--- analyzes the user provided `setup` parameters and sends a message if they use a deprecated option, then gives the new option to use. +--- +---@param options table: the options provided by the user. +---@private +function log.warn_deprecation(options) + local uses_deprecated_option = false + local notice = "is now deprecated, use `%s` instead." + local root_deprecated = { + foo = "bar", + bar = "baz", + } + + for name, warning in pairs(root_deprecated) do + if options[name] ~= nil then + uses_deprecated_option = true + log.notify( + "deprecated_options", + vim.log.levels.WARN, + true, + string.format("`%s` %s", name, string.format(notice, warning)) + ) + end + end + + if uses_deprecated_option then + log.notify( + "deprecated_options", + vim.log.levels.WARN, + true, + "sorry to bother you with the breaking changes :(" + ) + log.notify( + "deprecated_options", + vim.log.levels.WARN, + true, + "use `:h NeovimVivifyMarkdown.options` to read more." + ) + end +end + +return log diff --git a/plugin/neovim-vivify-markdown.lua b/plugin/neovim-vivify-markdown.lua new file mode 100644 index 0000000..521025d --- /dev/null +++ b/plugin/neovim-vivify-markdown.lua @@ -0,0 +1,19 @@ +-- SPDX-FileCopyrightText: 2024 Ali Sajid Imami +-- +-- SPDX-License-Identifier: MIT + +-- You can use this loaded variable to enable conditional parts of your plugin. +if _G.NeovimVivifyMarkdownLoaded then + return +end + +_G.NeovimVivifyMarkdownLoaded = true + +-- Useful if you want your plugin to be compatible with older (<0.7) neovim versions +if vim.fn.has("nvim-0.7") == 0 then + vim.cmd("command! NeovimVivifyMarkdown lua require('neovim-vivify-markdown').toggle()") +else + vim.api.nvim_create_user_command("NeovimVivifyMarkdown", function() + require("neovim-vivify-markdown").toggle() + end, {}) +end diff --git a/plugin/neovim-vivify-markdown.vim b/plugin/neovim-vivify-markdown.vim deleted file mode 100644 index 9e2076d..0000000 --- a/plugin/neovim-vivify-markdown.vim +++ /dev/null @@ -1,12 +0,0 @@ -if exists('g:loaded_neovim-vivify-markdown') | finish | endif - -" expose vim commands and interface here -" nnoremap PlugCommand :lua require(...).plug_command() - -let s:save_cpo = &cpo -set cpo&vim - -let g:loaded_neovim-vivify-markdown = 1 - -let &cpo = s:save_cpo -unlet s:save_cpo diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..8bc5cc9 --- /dev/null +++ b/renovate.json @@ -0,0 +1,25 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "assignees": [ + "AliSajid" + ], + "baseBranches": [ + "next" + ], + "extends": [ + "config:best-practices", + "group:definitelyTyped", + "group:githubArtifactActions", + "group:linters" + ], + "platformCommit": "enabled", + "pre-commit": { + "enabled": true + }, + "schedule": [ + "after 10pm every weekday", + "every weekend", + "before 5am every weekday" + ], + "semanticCommits": "enabled" +} diff --git a/scripts/minimal_init.lua b/scripts/minimal_init.lua new file mode 100644 index 0000000..0b71df3 --- /dev/null +++ b/scripts/minimal_init.lua @@ -0,0 +1,19 @@ +-- SPDX-FileCopyrightText: 2024 Ali Sajid Imami +-- +-- SPDX-License-Identifier: MIT + +-- Add current directory to 'runtimepath' to be able to use 'lua' files +vim.cmd([[let &rtp.=','.getcwd()]]) + +-- Set up 'mini.test' and 'mini.doc' only when calling headless Neovim (like with `make test` or `make documentation`) +if #vim.api.nvim_list_uis() == 0 then + -- Add 'mini.nvim' to 'runtimepath' to be able to use 'mini.test' + -- Assumed that 'mini.nvim' is stored in 'deps/mini.nvim' + vim.cmd("set rtp+=deps/mini.nvim") + + -- Set up 'mini.test' + require("mini.test").setup() + + -- Set up 'mini.doc' + require("mini.doc").setup() +end diff --git a/stylua.toml b/stylua.toml new file mode 100644 index 0000000..10fb56e --- /dev/null +++ b/stylua.toml @@ -0,0 +1,9 @@ +# SPDX-FileCopyrightText: 2024 Ali Sajid Imami +# +# SPDX-License-Identifier: CC0-1.0 + +indent_type = "Spaces" +indent_width = 4 +column_width = 100 +quote_style = "AutoPreferDouble" +no_call_parentheses = false diff --git a/tests/helpers.lua b/tests/helpers.lua new file mode 100644 index 0000000..028328f --- /dev/null +++ b/tests/helpers.lua @@ -0,0 +1,207 @@ +-- SPDX-FileCopyrightText: 2024 Ali Sajid Imami +-- +-- SPDX-License-Identifier: MIT + +-- imported from https://github.com/echasnovski/mini.nvim +local Helpers = {} + +-- Add extra expectations +Helpers.expect = vim.deepcopy(MiniTest.expect) + +local function error_message(str, pattern) + return string.format("Pattern: %s\nObserved string: %s", vim.inspect(pattern), str) +end + +Helpers.expect.buf_width = MiniTest.new_expectation( + "variable in child process matches", + function(child, field, value) + return Helpers.expect.equality( + child.lua_get( + "vim.api.nvim_win_get_width(_G.NeovimVivifyMarkdown.state." .. field .. ")" + ), + value + ) + end, + error_message +) + +Helpers.expect.global = MiniTest.new_expectation( + "variable in child process matches", + function(child, field, value) + return Helpers.expect.equality(child.lua_get(field), value) + end, + error_message +) + +Helpers.expect.global_type = MiniTest.new_expectation( + "variable type in child process matches", + function(child, field, value) + return Helpers.expect.global(child, "type(" .. field .. ")", value) + end, + error_message +) + +Helpers.expect.config = MiniTest.new_expectation( + "config option matches", + function(child, field, value) + if field == "" then + return Helpers.expect.global(child, "_G.NeovimVivifyMarkdown.config" .. field, value) + else + return Helpers.expect.global(child, "_G.NeovimVivifyMarkdown.config." .. field, value) + end + end, + error_message +) + +Helpers.expect.config_type = MiniTest.new_expectation( + "config option type matches", + function(child, field, value) + return Helpers.expect.global( + child, + "type(_G.NeovimVivifyMarkdown.config." .. field .. ")", + value + ) + end, + error_message +) + +Helpers.expect.state = MiniTest.new_expectation("state matches", function(child, field, value) + return Helpers.expect.global(child, "_G.NeovimVivifyMarkdown.state." .. field, value) +end, error_message) + +Helpers.expect.state_type = MiniTest.new_expectation( + "state type matches", + function(child, field, value) + return Helpers.expect.global( + child, + "type(_G.NeovimVivifyMarkdown.state." .. field .. ")", + value + ) + end, + error_message +) + +Helpers.expect.match = MiniTest.new_expectation("string matching", function(str, pattern) + return str:find(pattern) ~= nil +end, error_message) + +Helpers.expect.no_match = MiniTest.new_expectation("no string matching", function(str, pattern) + return str:find(pattern) == nil +end, error_message) + +-- Monkey-patch `MiniTest.new_child_neovim` with helpful wrappers +Helpers.new_child_neovim = function() + local child = MiniTest.new_child_neovim() + + local prevent_hanging = function(method) + if not child.is_blocked() then + return + end + + local msg = + string.format("Can not use `child.%s` because child process is blocked.", method) + error(msg) + end + + child.wait = function(ms) + child.loop.sleep(ms or 10) + end + + child.nnp = function() + child.cmd("NeovimVivifyMarkdown") + child.wait() + end + + child.get_wins_in_tab = function(tab) + tab = tab or "_G.NeovimVivifyMarkdown.state.active_tab" + + return child.lua_get("vim.api.nvim_tabpage_list_wins(" .. tab .. ")") + end + + child.list_buffers = function() + return child.lua_get("vim.api.nvim_list_bufs()") + end + + child.setup = function() + child.restart({ "-u", "scripts/minimal_init.lua" }) + + -- Change initial buffer to be readonly. This not only increases execution + -- speed, but more closely resembles manually opened Neovim. + child.bo.readonly = false + end + + child.get_current_win = function() + return child.lua_get("vim.api.nvim_get_current_win()") + end + + child.set_lines = function(arr, start, finish) + prevent_hanging("set_lines") + + if type(arr) == "string" then + arr = vim.split(arr, "\n") + end + + child.api.nvim_buf_set_lines(0, start or 0, finish or -1, false, arr) + end + + child.get_lines = function(start, finish) + prevent_hanging("get_lines") + + return child.api.nvim_buf_get_lines(0, start or 0, finish or -1, false) + end + + child.set_cursor = function(line, column, win_id) + prevent_hanging("set_cursor") + + child.api.nvim_win_set_cursor(win_id or 0, { line, column }) + end + + child.get_cursor = function(win_id) + prevent_hanging("get_cursor") + + return child.api.nvim_win_get_cursor(win_id or 0) + end + + child.set_size = function(lines, columns) + prevent_hanging("set_size") + + if type(lines) == "number" then + child.o.lines = lines + end + + if type(columns) == "number" then + child.o.columns = columns + end + end + + child.get_size = function() + prevent_hanging("get_size") + + return { child.o.lines, child.o.columns } + end + + --- Assert visual marks + --- + --- Useful to validate visual selection + --- + ---@param first number|table Table with start position or number to check linewise. + ---@param last number|table Table with finish position or number to check linewise. + ---@private + child.expect_visual_marks = function(first, last) + child.ensure_normal_mode() + + first = type(first) == "number" and { first, 0 } or first + last = type(last) == "number" and { last, 2147483647 } or last + + MiniTest.expect.equality(child.api.nvim_buf_get_mark(0, "<"), first) + MiniTest.expect.equality(child.api.nvim_buf_get_mark(0, ">"), last) + end + + child.expect_screenshot = function(opts, path, screenshot_opts) + MiniTest.expect.reference_screenshot(child.get_screenshot(screenshot_opts), path, opts) + end + + return child +end + +return Helpers diff --git a/tests/test_API.lua b/tests/test_API.lua new file mode 100644 index 0000000..5785edf --- /dev/null +++ b/tests/test_API.lua @@ -0,0 +1,56 @@ +-- SPDX-FileCopyrightText: 2024 Ali Sajid Imami +-- +-- SPDX-License-Identifier: MIT + +local Helpers = dofile("tests/helpers.lua") + +-- See https://github.com/echasnovski/mini.nvim/blob/main/lua/mini/test.lua for more documentation + +local child = Helpers.new_child_neovim() + +local T = MiniTest.new_set({ + hooks = { + -- This will be executed before every (even nested) case + pre_case = function() + -- Restart child process with custom 'init.lua' script + child.restart({ "-u", "scripts/minimal_init.lua" }) + end, + -- This will be executed one after all tests from this set are finished + post_once = child.stop, + }, +}) + +-- Tests related to the `setup` method. +T["setup()"] = MiniTest.new_set() + +T["setup()"]["sets exposed methods and default options value"] = function() + child.lua([[require('neovim-vivify-markdown').setup()]]) + + -- global object that holds your plugin information + Helpers.expect.global_type(child, "_G.NeovimVivifyMarkdown", "table") + + -- public methods + Helpers.expect.global_type(child, "_G.NeovimVivifyMarkdown.toggle", "function") + Helpers.expect.global_type(child, "_G.NeovimVivifyMarkdown.disable", "function") + Helpers.expect.global_type(child, "_G.NeovimVivifyMarkdown.enable", "function") + + -- config + Helpers.expect.global_type(child, "_G.NeovimVivifyMarkdown.config", "table") + + -- assert the value, and the type + Helpers.expect.config(child, "debug", false) + Helpers.expect.config_type(child, "debug", "boolean") +end + +T["setup()"]["overrides default values"] = function() + child.lua([[require('neovim-vivify-markdown').setup({ + -- write all the options with a value different than the default ones + debug = true, + })]]) + + -- assert the value, and the type + Helpers.expect.config(child, "debug", true) + Helpers.expect.config_type(child, "debug", "boolean") +end + +return T