Skip to content

Commit

Permalink
ci: style, lint dev: precommit, style, lint, editorconfig (#218)
Browse files Browse the repository at this point in the history
* add stylua, luacheck, luarc, editorconfig, pre-commit hooks

* add stylua, luacheck, luarc, editorconfig, pre-commit hooks

* add comments before icons_by_filename and icons_by_file_extension

* stylua nit for generated light

* correct luacheck stylua order in contributing.md

* add stylua/luacheck OS package notes

* use make instead of pre-commit hooks

* document prerequisites

* remove setup-hooks.sh

* ci: add pre-commit configuration and GHA (#233)

* ci: add pre-commit configuration

* ci: add GHA to autoupdate pre-commit hooks

---------

Co-authored-by: gegoune <[email protected]>
  • Loading branch information
alex-courtis and gegoune authored Mar 20, 2023
1 parent 585dbc2 commit 4970f75
Show file tree
Hide file tree
Showing 12 changed files with 216 additions and 124 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
insert_final_newline = true
end_of_line = lf

[*.lua]
indent_style = space
indent_size = 2
27 changes: 27 additions & 0 deletions .github/workflows/pre-commit-autoupdate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Pre-commit autoupdate
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
auto-update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/[email protected]
- run: pip install pre-commit
shell: bash
- run: pre-commit autoupdate
shell: bash
- run: pre-commit run --all-files
shell: bash
- uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: update/pre-commit-hooks
title: "chore: update pre-commit hooks"
commit-message: "chore: update pre-commit hooks"
body: Update versions of pre-commit hooks to latest version.
7 changes: 7 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
max_line_length = 120

globals = {
"vim",
"jit",
"bit",
}
12 changes: 12 additions & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"runtime.version" : "Lua 5.1",
"diagnostics": {
"globals": [
"vim",
"jit",
"bit"
]
}
}

21 changes: 21 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
repos:
- repo: https://github.com/johnnymorganz/stylua
rev: v0.17.0
hooks:
- id: stylua-github
- repo: local
hooks:
- id: luacheck
name: Luacheck
description: Lints Lua files using Luacheck.
entry: luacheck --
language: system
types: [lua]
- repo: local
hooks:
- id: lighttheme
name: Light Color Scheme Generator
description: Ensures Light Color Scheme version has been generated.
entry: nvim --headless -c 'source scripts/generate_colors.lua' -c 'qall'
language: system
types: [lua]
6 changes: 6 additions & 0 deletions .stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
column_width = 120
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferDouble"
call_parentheses = "None"
43 changes: 37 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,43 @@ Please name your commits and the PR simply e.g.
update makefile icon
update .kt colors

## Prerequisites

Add [vim-colortemplate](https://github.com/lifepillar/vim-colortemplate) to &runtimepath. The easiest way to do this is via your package manager.

Code is formatted using stylua and linted using luacheck.

You can install these with:
```sh
cargo install stylua
luarocks install luacheck
```

or via your OS package manager e.g. Arch linux:
```sh
pacman -S stylua
pacman -S luacheck
```

## Building

Following your changes, please run:

```sh
make
```

This will:
1. Generate cterm colors
2. Generate light color variants
3. Check style
4. Lint

You can automatically fix any style issues via:
```sh
make style-fix
```

## Generate Colors

Add or update icons in `scripts/nvim-web-devicons.lua`.
Expand Down Expand Up @@ -37,19 +74,13 @@ ___Key/value pairs must appear in the same exact order!___
- `cterm_color` must be below `color`, and it must contain a number (any number)
- the correct value for `cterm_color` will be generated by the script

Add [vim-colortemplate](https://github.com/lifepillar/vim-colortemplate) to &runtimepath. The easiest way to do this is via your package manager.

Ensure your current working directory is the repo root.
Run `make`. This will:
- Update `cterm_color` based on `color`
- Generate `nvim-web-devicons-light.lua`

Please commit both `nvim-web-devicons.lua` and `nvim-web-devicons-light.lua`

## Styling And Format

TODO @alex-courtis

## Pull Request

Please reference any issues in the description e.g. "resolves #1234".
Expand Down
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
all: colors style-check lint

colors:
nvim --headless -c 'source scripts/generate_colors.lua' -c 'qall'

all: colors
style-check:
stylua . --check

style-fix:
stylua .

lint:
luacheck .

.PHONY: all colors style-check style-fix lint
20 changes: 10 additions & 10 deletions lua/nvim-web-devicons-light.lua
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ local icons_by_filename = {
cterm_color = "22",
name = "Vimrc",
},
['package.json'] = {
["package.json"] = {
icon = "",
color = "#ae1d38",
name = "PackageJson"
name = "PackageJson",
},
['package-lock.json'] = {
["package-lock.json"] = {
icon = "",
color = "#7a0d21",
name = "PackageLockJson"
name = "PackageLockJson",
},
["node_modules"] = {
icon = "",
Expand Down Expand Up @@ -591,7 +591,7 @@ local icons_by_file_extension = {
color = "#33312b",
icon = "🌜",
cterm_color = "236",
name = "Fennel"
name = "Fennel",
},
["fish"] = {
icon = "",
Expand Down Expand Up @@ -669,13 +669,13 @@ local icons_by_file_extension = {
icon = "",
color = "#ac2880",
cterm_color = "126",
name = "GraphQL"
name = "GraphQL",
},
["gql"] = {
icon = "",
color = "#ac2880",
cterm_color = "126",
name = "GraphQL"
name = "GraphQL",
},
["h"] = {
icon = "",
Expand Down Expand Up @@ -825,13 +825,13 @@ local icons_by_file_extension = {
icon = "",
color = "#158197",
cterm_color = "31",
name = "JavaScriptReactTest"
name = "JavaScriptReactTest",
},
["spec.jsx"] = {
icon = "",
color = "#158197",
cterm_color = "31",
name = "JavaScriptReactSpec"
name = "JavaScriptReactSpec",
},
["ksh"] = {
icon = "",
Expand Down Expand Up @@ -1544,5 +1544,5 @@ local icons_by_file_extension = {

return {
icons_by_filename = icons_by_filename,
icons_by_file_extension = icons_by_file_extension
icons_by_file_extension = icons_by_file_extension,
}
Loading

0 comments on commit 4970f75

Please sign in to comment.