Skip to content

Commit

Permalink
Merge pull request #5 from Dich0tomy/feat/add-collaborators-consisten…
Browse files Browse the repository at this point in the history
…cy-config

Feat/add collaborators consistency config
  • Loading branch information
Dich0tomy authored Jul 14, 2024
2 parents 2ccb993 + 948a4bd commit 0e90b8b
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 62 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = tab
indent_width = 2
charset = utf-8

[*.{nix,yaml,yml}]
indent_style = spaces
indent_width = 2
1 change: 1 addition & 0 deletions .github/workflows/lua-tests.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Run tests
on:
pull_request:
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/luarocks.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Push to Luarocks

on:
Expand All @@ -8,11 +9,11 @@ on:
workflow_dispatch:

jobs:
# luarocks-upload:
# runs-on: ubuntu-22.04
# steps:
# - uses: actions/checkout@v3
# - name: LuaRocks Upload
# uses: nvim-neorocks/luarocks-tag-release@v5
# env:
# LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }}
luarocks-upload:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
# - name: LuaRocks Upload
# uses: nvim-neorocks/luarocks-tag-release@v5
# env:
# LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }}
1 change: 1 addition & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Release Please

on:
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
/*

#GH, git
# GH, git
!.gitignore
!.github/

# Meta
!LICENSE
!TODO.md

# Collaborators consistency
!.editorconfig
!stylua.toml
!.pre-commit-config.yaml
!git-conventional-commits.yaml

# Nix
!nix/
!default.nix
Expand Down
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/rhysd/actionlint
rev: v1.7.1
hooks:
- id: actionlint

- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: yamllint

- repo: https://github.com/crate-ci/typos
rev: v1.23.2
hooks:
- id: typos

- repo: https://github.com/qoomon/git-conventional-commits
rev: v2.6.7
hooks:
- id: conventional-commits

- repo: https://github.com/JohnnyMorganz/StyLua
rev: v0.20.0
hooks:
- id: stylua-github
2 changes: 1 addition & 1 deletion docs/tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ mkShell {

This is due to the fact that these are guarded by special "feature test macros" of form `__cpp_lib_x`, `__cpp_has_x`, etc.

If you already have `clangd` configured you can go to defintion on the header. It should be guarded by something akin to this:
If you already have `clangd` configured you can go to definition on the header. It should be guarded by something akin to this:
```cpp
#if __cplusplus > 202002L && __cpp_concepts >= 202002L
```
Expand Down
14 changes: 14 additions & 0 deletions git-conventional-commits.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
convention:
commitTypes:
- feat
- fix
- perf
- ref
- style
- test
- build
- docs
- env
- chore
releaseTagGlobPattern: v?[0-9]*.[0-9]*.[0-9]*
30 changes: 15 additions & 15 deletions lua/cpp-tools/lib/iter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ function M.line_count(str)
for i = 1, length - 1 do
local c = str:sub(i, i)
if c == '\n' then
if (i ~= (length - 2)) then
count = count + 1
end
end
if i ~= (length - 2) then
count = count + 1
end
end
end

return count
Expand All @@ -31,19 +31,19 @@ end
---@param arr2 T[] second array
---@return boolean # are the arrays equal
function M.arrays_equal(arr1, arr2)
if arr1 == arr2 then
return true
elseif #arr1 ~= #arr2 then
return false
end
if arr1 == arr2 then
return true
elseif #arr1 ~= #arr2 then
return false
end

for i = 1, #arr1 do
if arr1[i] ~= arr2[i] then
return false
end
end
for i = 1, #arr1 do
if arr1[i] ~= arr2[i] then
return false
end
end

return true
return true
end

return M
8 changes: 8 additions & 0 deletions nix/checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
overlays = [inputs.neorocks.overlays.default];
};

checks.pre-commit = pkgs.writeShellApplication {
name = "pre-commit-check";

runtimeInputs = [pkgs.pre-commit];

text = "pre-commit run --all-files";
};

checks.default = pkgs.writeShellApplication {
name = "typos-check";

Expand Down
14 changes: 13 additions & 1 deletion nix/shell.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
{pkgs, ...}: {
{pkgs, lib, ...}: {
devShells.default = pkgs.mkShellNoCC {
shellHook = ''
${lib.getExe pkgs.pre-commit} install
'';

packages = [
pkgs.lua-language-server
pkgs.luajitPackages.luacheck
pkgs.luarocks

pkgs.pre-commit
pkgs.ruby
pkgs.stylua
pkgs.typos
pkgs.yamllint
pkgs.actionlint
];
};
}
72 changes: 36 additions & 36 deletions spec/iter_spec.lua
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
describe('array_equals', function()
local iter = require('cpp-tools.lib.iter')
local iter = require('cpp-tools.lib.iter')

it('Two same references to empty are equal', function()
local empty = {}
local a = empty
local b = empty
it('Two same references to empty are equal', function()
local empty = {}
local a = empty
local b = empty

assert.is.truthy(iter.arrays_equal(a, b))
end)
assert.is.truthy(iter.arrays_equal(a, b))
end)

it('Two different references to empty are equal', function()
local a = {}
local b = {}
it('Two different references to empty are equal', function()
local a = {}
local b = {}

assert.is.truthy(iter.arrays_equal(a, b))
end)
assert.is.truthy(iter.arrays_equal(a, b))
end)

it('Two same values are equal', function()
local a = { 1, 2 }
local b = { 1, 2 }
it('Two same values are equal', function()
local a = { 1, 2 }
local b = { 1, 2 }

assert.is.truthy(iter.arrays_equal(a, b))
end)
assert.is.truthy(iter.arrays_equal(a, b))
end)

it('Two same values with different order are not equal', function()
local a = { 1, 2 }
local b = { 2, 1 }
it('Two same values with different order are not equal', function()
local a = { 1, 2 }
local b = { 2, 1 }

assert.is.falsy(iter.arrays_equal(a, b))
end)
assert.is.falsy(iter.arrays_equal(a, b))
end)

it('Two same values with different values', function()
local a = { '' }
local b = { 1 }
it('Two same values with different values', function()
local a = { '' }
local b = { 1 }

assert.is.falsy(iter.arrays_equal(a, b))
end)
assert.is.falsy(iter.arrays_equal(a, b))
end)
end)

describe('line_count', function()
Expand All @@ -45,17 +45,17 @@ describe('line_count', function()
assert.are.equal(iter.line_count(''), 1)
end)

it('Returns 1 for a non empty string with one line', function()
assert.are.equal(iter.line_count('Hello there'), 1)
end)
it('Returns 1 for a non empty string with one line', function()
assert.are.equal(iter.line_count('Hello there'), 1)
end)

it('Returns 1 for a string with a trailing newlien', function()
assert.are.equal(iter.line_count('Foo\n'), 1)
end)
it('Returns 1 for a string with a trailing newlien', function()
assert.are.equal(iter.line_count('Foo\n'), 1)
end)

it('Returns 2 for a string with a trailing newline and content after it', function()
assert.are.equal(iter.line_count('Foo\nBar'), 2)
end)
it('Returns 2 for a string with a trailing newline and content after it', function()
assert.are.equal(iter.line_count('Foo\nBar'), 2)
end)

it('Returns X for a string with X lines (ignoring last newline)', function()
local three_lined_string = [[
Expand Down
7 changes: 7 additions & 0 deletions stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
column_width = 120
line_endings = 'Unix'
indent_type = 'Tabs'
indent_width = 2
quote_style = 'ForceSingle'
call_parentheses = 'Always'
collapse_simple_statement = 'Never'

0 comments on commit 0e90b8b

Please sign in to comment.