Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add CI for formatting #249

Merged
merged 4 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permissions:
contents: read

jobs:
build:
test:
runs-on: ${{ matrix.runner }}

strategy:
Expand Down Expand Up @@ -71,6 +71,10 @@ jobs:
- name: Remove grit modules
run: rm -rf .grit/.gritmodules

- name: check formatting
run: |
grit format

- name: Run grit patterns test
run: |
if [ -n "${{ secrets.API_CLIENT_ID }}" ] && [ -n "${{ secrets.API_CLIENT_SECRET }}" ]; then
Expand Down
25 changes: 1 addition & 24 deletions .grit/grit.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,2 @@
version: 0.0.1
patterns:
- name: grit_snake_case
description: Markdown files committed to stdlib's patterns directory must have names conforming to GritQL's pattern name convention.
body: |
engine marzano(0.1)
language markdown

file($name, $body) where {
$name <: r".*?/?([^/]+)\.[a-zA-Z]*"($base_name),
! $base_name <: r"^[a-zA-Z_][a-zA-Z0-9_]*$"
}
samples:
- input: |
<!-- @filename: .grit/patterns/kebab-case.md -->

# This is a markdown file
output: |
<!-- @filename: .grit/patterns/kebab-case.md -->

# This is a markdown file
- input: |
<!-- @filename: .grit/patterns/snake_case.md -->

# This is a markdown file
patterns: []
5 changes: 2 additions & 3 deletions .grit/patterns/go/mux_go_v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ pattern rename_params() {

pattern final_mux_renames() {
or {
`[]$muxgo.InputSettings{$params}` where {}
// $video = require_import(source=`github.com/muxinc/mux-go/video`),
=> `[]video.AssetNewParamsInput{$params}`
`[]$muxgo.InputSettings{$params}` => `[]video.AssetNewParamsInput{$params}`
// $video = require_import(source=`github.com/muxinc/mux-go/video`),
}
}

Expand Down
39 changes: 39 additions & 0 deletions .grit/patterns/grit_snake_case.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Use snake case for pattern names

Markdown files committed to stdlib's patterns directory must have names conforming to GritQL's pattern name convention.

```grit
engine marzano(0.1)
language markdown

file($name, $body) where {
$name <: r".*?/?([^/]+)\.[a-zA-Z]*"($base_name),
! $base_name <: r"^[a-zA-Z_][a-zA-Z0-9_]*$"
}
```

## Examples

### Invalid

```md
<!-- @filename: .grit/patterns/kebab-case.md -->

# This is a markdown file
```

Still bad:

```md
<!-- @filename: .grit/patterns/kebab-case.md -->

# This is a markdown file
```

### Valid

```md
<!-- @filename: .grit/patterns/snake_case.md -->

# This is a markdown file
```
6 changes: 4 additions & 2 deletions .grit/patterns/js/replace_wildcard_imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ pattern replace_wildcard_import() {
$refs = distinct($refs),
$joined_refs = join($refs, `, `),
// Try the different scenarios
if ($refs <: []) {}
if ($refs <: []) {} else if (and {
// Found nothing, leave the wildcard
else if (and { ! $refs <: [], $kept_refs <: [] }) {
! $refs <: [],
$kept_refs <: []
}) {
// Found just refs we can replace, replace them
$import => `import { $joined_refs } from $src`
} else {
Expand Down
5 changes: 5 additions & 0 deletions .grit/patterns/python/_test_replace_import_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,33 @@ language python
find_replace_imports(list=[
[
`langchain_community.chat_models`, `ChatOpenAI`, `langchain_openai`,

`ChatOpenAI`
],

[`anthropic_place`, `EpicLinguist`, `new_anthropic_place`, `SauceLinguist`],

[
`langchain_community.chat_models`, `MyLittleModel`, `extra_lc_models`,

`MyBigModel`
],

[
`langchain.chains.ernie_functions.base`, `convert_to_ernie_function`,

`langchain_community.chains`, `convert_to_ernie_function`
],

[
`langchain.chains.ernie_functions.base`, `create_ernie_fn_chain`,

`langchain_community.chains`, `create_ernie_fn_chain`
],

[
`langchain.chains.graph_qa.cypher_utils`, `CypherQueryCorrector`, `lc_new`,

`CypherQueryCorrector`
],

Expand Down
Loading