Skip to content

Commit 815a363

Browse files
first iteration of codacy-ruff (#1)
* First version of Codacy-Ruff * Created Doc generator * Improved the wrapper to allow configuration files * Created multiple-tests
1 parent 0d386dd commit 815a363

File tree

752 files changed

+25734
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

752 files changed

+25734
-5
lines changed

.circleci/config.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
version: 2.1
2+
3+
orbs:
4+
codacy: codacy/base@12.1.4
5+
codacy_plugins_test: codacy/plugins-test@2.0.11
6+
7+
workflows:
8+
version: 2
9+
compile_test_deploy:
10+
jobs:
11+
- codacy/checkout_and_version
12+
- codacy/shell:
13+
name: publish_docker_local
14+
cmd: |
15+
docker build -t $CIRCLE_PROJECT_REPONAME:latest .
16+
docker save --output docker-image.tar $CIRCLE_PROJECT_REPONAME:latest
17+
persist_to_workspace: true
18+
requires:
19+
- codacy/checkout_and_version
20+
- codacy_plugins_test/run:
21+
name: plugins_test
22+
run_multiple_tests: true
23+
run_json_tests: false
24+
run_pattern_tests: false
25+
requires:
26+
- publish_docker_local
27+
- codacy/publish_docker:
28+
context: CodacyDocker
29+
requires:
30+
- publish_docker_local
31+
filters:
32+
branches:
33+
only:
34+
- master
35+
- codacy/tag_version:
36+
name: tag_version
37+
context: CodacyAWS
38+
requires:
39+
- codacy/publish_docker

.codacyrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"tools": [
3+
{
4+
"name": "ruff"
5+
}
6+
]
7+
}

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @codacy/macgyvers

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.ruff_cache/

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM python:3.13-alpine3.21
2+
3+
COPY requirements.txt requirements.txt
4+
5+
RUN apk add --no-cache --update bash && \
6+
pip3 install --no-cache-dir -r requirements.txt
7+
8+
COPY src/codacy_ruff.py codacy_ruff.py
9+
10+
COPY /docs /docs
11+
12+
RUN adduser -u 2004 -D docker
13+
14+
RUN chown -R docker:docker /docs /home/docker
15+
16+
RUN chown -R docker:docker /home/docker
17+
18+
USER docker
19+
20+
ENTRYPOINT [ "python" ]
21+
22+
CMD [ "codacy_ruff.py" ]

LICENSE

Lines changed: 1398 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,59 @@
1-
# codacy-public-template
1+
# Codacy Ruff
22

3-
Template repository for new public repositories.
3+
Co-authored by @valeriupredoi
44

5-
## GitHub actions
5+
This is the docker engine we use at Codacy to have [Ruff](https://docs.astral.sh/ruff/) support.
6+
You can also create a docker to integrate the tool and language of your choice!
7+
See the [codacy-engine-scala-seed](https://github.com/codacy/codacy-engine-scala-seed) repository for more information.
68

7-
This repository has the common GitHub actions that we want to have accross all of our public repositories.
8-
They should be kept at `.github/workflows`
9+
## Python compatibility
10+
Ruff is compatible with Python 3.13
11+
12+
## Usage
13+
14+
You can create the docker by doing:
15+
16+
```bash
17+
docker build --no-cache -t codacy-ruff:latest .
18+
```
19+
20+
The docker is ran with the following command:
21+
22+
```bash
23+
docker run -it -v $srcDir:/src codacy-ruff:latest
24+
```
25+
26+
## Generate Docs
27+
28+
1. Update the version in `requirements.txt`
29+
30+
2. Run the DocGenerator to update all the patterns/descriptions and the patterns.xml (from all-patterns test)
31+
32+
```bash
33+
python<version> src/doc_generator.py
34+
```
35+
36+
## Test
37+
38+
We use the [codacy-plugins-test](https://github.com/codacy/codacy-plugins-test) to test our external tools integration.
39+
You can follow the instructions there to make sure your tool is working as expected.
40+
41+
## What is Codacy?
42+
43+
[Codacy](https://www.codacy.com/) is an Automated Code Review Tool that monitors your technical debt, helps you improve your code quality, teaches best practices to your developers, and helps you save time in Code Reviews.
44+
45+
### Among Codacy’s features:
46+
47+
- Identify new Static Analysis issues
48+
- Commit and Pull Request Analysis with GitHub, BitBucket/Stash, GitLab (and also direct git repositories)
49+
- Auto-comments on Commits and Pull Requests
50+
- Integrations with Slack, HipChat, Jira, YouTrack
51+
- Track issues in Code Style, Security, Error Proneness, Performance, Unused Code and other categories
52+
53+
Codacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity.
54+
55+
Codacy supports PHP, Python, Ruby, Java, JavaScript, and Scala, among others.
56+
57+
### Free for Open Source
58+
59+
Codacy is free for Open Source projects.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# builtin-variable-shadowing (A001)
2+
Derived from the flake8-builtins linter.
3+
## What it does
4+
Checks for variable (and function) assignments that use the same names
5+
as builtins.
6+
## Why is this bad?
7+
Reusing a builtin name for the name of a variable increases the
8+
difficulty of reading and maintaining the code, and can cause
9+
non-obvious errors, as readers may mistake the variable for the
10+
builtin and vice versa.
11+
Builtins can be marked as exceptions to this rule via the
12+
lint.flake8-builtins.builtins-ignorelist configuration option.
13+
## Example
14+
```
15+
def find_max(list_of_lists):
16+
max = 0
17+
for flat_list in list_of_lists:
18+
for value in flat_list:
19+
max = max(max, value) # TypeError: 'int' object is not callable
20+
return max
21+
```
22+
## Use instead:
23+
```
24+
def find_max(list_of_lists):
25+
result = 0
26+
for flat_list in list_of_lists:
27+
for value in flat_list:
28+
result = max(result, value)
29+
return result
30+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# builtin-argument-shadowing (A002)
2+
Derived from the flake8-builtins linter.
3+
## What it does
4+
Checks for function arguments that use the same names as builtins.
5+
## Why is this bad?
6+
Reusing a builtin name for the name of an argument increases the
7+
difficulty of reading and maintaining the code, and can cause
8+
non-obvious errors, as readers may mistake the argument for the
9+
builtin and vice versa.
10+
Builtins can be marked as exceptions to this rule via the
11+
lint.flake8-builtins.builtins-ignorelist configuration option.
12+
## Example
13+
```
14+
def remove_duplicates(list, list2):
15+
result = set()
16+
for value in list:
17+
result.add(value)
18+
for value in list2:
19+
result.add(value)
20+
return list(result) # TypeError: 'list' object is not callable
21+
```
22+
## Use instead:
23+
```
24+
def remove_duplicates(list1, list2):
25+
result = set()
26+
for value in list1:
27+
result.add(value)
28+
for value in list2:
29+
result.add(value)
30+
return list(result)
31+
```
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# builtin-attribute-shadowing (A003)
2+
Derived from the flake8-builtins linter.
3+
## What it does
4+
Checks for class attributes and methods that use the same names as
5+
Python builtins.
6+
## Why is this bad?
7+
Reusing a builtin name for the name of an attribute increases the
8+
difficulty of reading and maintaining the code, and can cause
9+
non-obvious errors, as readers may mistake the attribute for the
10+
builtin and vice versa.
11+
Since methods and class attributes typically cannot be referenced directly
12+
from outside the class scope, this rule only applies to those methods
13+
and attributes that both shadow a builtin and are referenced from within
14+
the class scope, as in the following example, where the list[int] return
15+
type annotation resolves to the list method, rather than the builtin:
16+
class Class:
17+
@staticmethod
18+
def list() -> None:
19+
pass
20+
@staticmethod
21+
def repeat(value: int, times: int) -> list[int]:
22+
return [value] * times
23+
Builtins can be marked as exceptions to this rule via the
24+
lint.flake8-builtins.builtins-ignorelist configuration option, or
25+
converted to the appropriate dunder method. Methods decorated with
26+
@typing.override or @typing_extensions.override are also
27+
ignored.
28+
## Example
29+
```
30+
class Class:
31+
@staticmethod
32+
def list() -> None:
33+
pass
34+
@staticmethod
35+
def repeat(value: int, times: int) -> list[int]:
36+
return [value] * times
37+
```

0 commit comments

Comments
 (0)