Skip to content

Commit

Permalink
Merge branch 'master' into code-style-initialize-objects-with-properties
Browse files Browse the repository at this point in the history
  • Loading branch information
kgrubb authored Jul 17, 2024
2 parents 04a81d0 + 8ae2bb6 commit 990eb42
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 32 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- id: vala-lint
name: Vala-Lint
language: docker_image
entry: --entrypoint /usr/bin/io.elementary.vala-lint valalang/lint:latest --fix
description: Check Vala code files for code-style errors.
files: \.vala$
3 changes: 3 additions & 0 deletions .valalintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
po
data
build
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN mkdir -p /opt/vala-lint-portable
COPY . /opt/vala-lint

RUN apt-get update \
&& apt-get install -y --no-install-recommends gcc libvala-dev valac meson\
&& apt-get install -y gcc libjson-glib-dev libvala-dev valac meson\
&& cd /opt/vala-lint \
&& meson build --prefix=/usr \
&& cd build \
Expand All @@ -23,7 +23,7 @@ ENV DEBIAN_FRONTEND=noninteractive
COPY --from=0 /opt/vala-lint-portable /

RUN apt-get update \
&& apt-get install -y --no-install-recommends libvala-dev gio-2.0 \
&& apt-get install -y --no-install-recommends libvala-dev gio-2.0 libjson-glib-1.0-0 \
&& mkdir -p /app \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
Expand Down
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<img src="https://github.com/vala-lang/vala-lint/workflows/Publish/badge.svg" alt="Publish">

<a href="https://hub.docker.com/r/valalang/lint">
<img src="https://img.shields.io/docker/stars/valalang/lint" alt="Dockerhub">
<img src="https://img.shields.io/docker/stars/valalang/lint" alt="Dockerhub">
</a>

<a href="https://www.bountysource.com/trackers/45980444-elementary-Vala-lint">
Expand Down Expand Up @@ -123,8 +123,46 @@ If you want to skip an entire file, you can use

at the beginning of the file.

### Ignoring Files
You can disable linting of files matching certain patterns by creating a `.valalintignore` text file.
If the file is created in your home directory it will be applied globally.
The patterns must be like those used for globbing filenames. Type `man glob` into a terminal
for further information.

If the file is created in the root directory of your project it will apply only to that project and
will override any global setting.
If no `.valalintignore` file is found then the patterns in any `.gitignore` file found in the
project root are ignored.

The format of the file is one pattern per line. Usually you would want to ignore certain folders like

```vala
build
po
data
```

Note that if you do provide a `.valalintignore` file, you must repeat any patterns in a `.gitignore`
file that you do not want to lint.

Although `vala-lint` ignores non-Vala files, ignoring large directories significantly speeds up linting.

You may also ignore specific kinds of `.vala` files like
```vala
~*.vala
```

### Docker and Continuous Integration
Vala-Lint is primarily intended to be used in Continuous Integration (CI). It's available in a convenient, always up-to-date Docker container `valalang/lint:latest` hosted on Docker Hub.

docker run -v "$PWD":/app valalang/lint:latest

### pre-commit Integration
You can use Vala-Lint via [pre-commit](https://pre-commit.com/) by adding the following entry to your `.pre-commit-config.yaml`:

```yaml
- repo: https://github.com/vala-lang/vala-lint
rev: master
hooks:
- id: vala-lint
```
8 changes: 4 additions & 4 deletions lib/Fixer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

public class ValaLint.Fixer : Object {
public void apply_fixes_for_file (File file, ref Vala.ArrayList<FormatMistake?> mistakes) throws Error, IOError {
var filename = file.get_path ();
string contents;
FileUtils.get_contents (filename, out contents);
uint8[] contents_data;
file.load_contents (null, out contents_data, null);
string contents = (string) (owned) contents_data;

var remaining_mistakes = new Vala.ArrayList<FormatMistake?> ((a, b) => a.equal_to (b));

Expand All @@ -46,6 +46,6 @@ public class ValaLint.Fixer : Object {
return a.begin.line - b.begin.line;
});

FileUtils.set_contents (filename, contents);
file.replace_contents (contents.data, null, false, FileCreateFlags.NONE, null);
}
}
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ gio_dep = dependency('gio-2.0', version: '>=2.56.4')
posix_dep = valac.find_library('posix')
libvala_required_version = '>= 0.40.4'
libvala_dep = dependency('libvala-@0@'.format(libvala_version), version: libvala_required_version)
json_dep = dependency('json-glib-1.0')

subdir('lib')
subdir('src')
Expand Down
Loading

0 comments on commit 990eb42

Please sign in to comment.