Skip to content

Commit 748bb7b

Browse files
CI Linting (#267)
* adds linting configuration and workflow * update error codes * reformat linting ignore rules * add patch to to ignore hooks * run linter * fix formatting error
1 parent 2f54c47 commit 748bb7b

File tree

123 files changed

+35147
-30201
lines changed

Some content is hidden

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

123 files changed

+35147
-30201
lines changed

.bazelrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ build --protocopt=--experimental_allow_proto3_optional
88
# parameter 'user_link_flags' is deprecated and will be removed soon.
99
# It may be temporarily re-enabled by setting --incompatible_require_linker_input_cc_api=false
1010
build --incompatible_require_linker_input_cc_api=false
11-

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.5.0
1+
6.5.0

.github/workflows/ci-lint.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: pre-commit
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [master]
7+
8+
jobs:
9+
pre-commit:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/[email protected]
13+
with:
14+
# Ensure the full history is fetched
15+
# This is required to run pre-commit on a specific set of commits
16+
# TODO: Remove this when all the pre-commit issues are fixed
17+
fetch-depth: 0
18+
- uses: actions/[email protected]
19+
with:
20+
python-version: 3.13
21+
- uses: pre-commit/[email protected]

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,4 @@ dmypy.json
126126
.pyre/
127127

128128
# pb2.py files
129-
*_pb2.py
129+
*_pb2.py

.pre-commit-config.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# pre-commit is a tool to perform a predefined set of tasks manually and/or
2+
# automatically before git commits are made.
3+
#
4+
# Config reference: https://pre-commit.com/#pre-commit-configyaml---top-level
5+
#
6+
# Common tasks
7+
#
8+
# - Register git hooks: pre-commit install --install-hooks
9+
# - Run on all files: pre-commit run --all-files
10+
#
11+
# These pre-commit hooks are run as CI.
12+
#
13+
# NOTE: if it can be avoided, add configs/args in pyproject.toml or below instead of creating a new `.config.file`.
14+
# https://pre-commit.ci/#configuration
15+
ci:
16+
autoupdate_schedule: monthly
17+
autofix_commit_msg: |
18+
[pre-commit.ci] Apply automatic pre-commit fixes
19+
20+
repos:
21+
# general
22+
- repo: https://github.com/pre-commit/pre-commit-hooks
23+
rev: v4.6.0
24+
hooks:
25+
- id: end-of-file-fixer
26+
exclude: '\.svg$|\.patch$'
27+
- id: trailing-whitespace
28+
exclude: '\.svg$|\.patch$'
29+
- id: check-json
30+
- id: check-yaml
31+
args: [--allow-multiple-documents, --unsafe]
32+
- id: check-toml
33+
34+
- repo: https://github.com/astral-sh/ruff-pre-commit
35+
rev: v0.5.6
36+
hooks:
37+
- id: ruff
38+
args: ["--fix"]
39+
- id: ruff-format

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,3 @@ tag.
238238
* [TensorFlow Data Validation PyPI](https://pypi.org/project/tensorflow-data-validation/)
239239
* [TensorFlow Data Validation Paper](https://mlsys.org/Conferences/2019/doc/2019/167.pdf)
240240
* [TensorFlow Data Validation Slides](https://conf.slac.stanford.edu/xldb2018/sites/xldb2018.conf.slac.stanford.edu/files/Tues_09.45_NeoklisPolyzotis_Data%20Analysis%20and%20Validation%20(1).pdf)
241-

g3doc/custom_data_validation.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,3 @@ See the
4343
[documentation](https://github.com/tensorflow/data-validation/blob/master/tensorflow_data_validation/anomalies/proto/custom_validation_config.proto)
4444
in the `CustomValidationConfig` proto for example
4545
configurations.
46-
47-

pyproject.toml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,130 @@ requires = [
1919
# Required for using org_tensorflow bazel repository.
2020
"numpy~=1.22.0",
2121
]
22+
23+
[tool.ruff]
24+
line-length = 88
25+
26+
[tool.ruff.lint]
27+
select = [
28+
# pycodestyle
29+
"E",
30+
"W",
31+
# Pyflakes
32+
"F",
33+
# pyupgrade
34+
"UP",
35+
# flake8-bugbear
36+
"B",
37+
# flake8-simplify
38+
"SIM",
39+
# isort
40+
"I",
41+
# pep8 naming
42+
"N",
43+
# pydocstyle
44+
"D",
45+
# annotations
46+
"ANN",
47+
# debugger
48+
"T10",
49+
# flake8-pytest
50+
"PT",
51+
# flake8-return
52+
"RET",
53+
# flake8-unused-arguments
54+
"ARG",
55+
# flake8-fixme
56+
"FIX",
57+
# flake8-eradicate
58+
"ERA",
59+
# pandas-vet
60+
"PD",
61+
# numpy-specific rules
62+
"NPY",
63+
]
64+
65+
ignore = [
66+
"D104", # Missing docstring in public package
67+
"D100", # Missing docstring in public module
68+
"D211", # No blank line before class
69+
"PD901", # Avoid using 'df' for pandas dataframes. Perfectly fine in functions with limited scope
70+
"ANN201", # Missing return type annotation for public function (makes no sense for NoneType return types...)
71+
"ANN101", # Missing type annotation for `self`
72+
"ANN204", # Missing return type annotation for special method
73+
"ANN002", # Missing type annotation for `*args`
74+
"ANN003", # Missing type annotation for `**kwargs`
75+
"D105", # Missing docstring in magic method
76+
"D203", # 1 blank line before after class docstring
77+
"D204", # 1 blank line required after class docstring
78+
"D413", # 1 blank line after parameters
79+
"SIM108", # Simplify if/else to one line; not always clearer
80+
"D206", # Docstrings should be indented with spaces; unnecessary when running ruff-format
81+
"E501", # Line length too long; unnecessary when running ruff-format
82+
"W191", # Indentation contains tabs; unnecessary when running ruff-format
83+
84+
# REMOVE AFTER FIXING
85+
# ANN rules (flake8-annotations)
86+
"ANN001", # Missing type annotation for function argument `args`
87+
"ANN102", # Missing type annotation for `cls` in classmethod
88+
"ANN202", # Missing Missing return type annotation for private function
89+
"ANN205", # Missing return type annotation for staticmethod
90+
"ANN206", # Missing return type annotation for classmethod
91+
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed in `domain`
92+
# ARG rules (flake8-unused-arguments)
93+
"ARG001", # Unused function argument
94+
"ARG002", # Unused method argument
95+
# B rules (flake8-bugbear)
96+
"B005", # Using `.strip()` with multi-character strings is misleading
97+
"B007", # Loop control variable not used within loop body
98+
"B008", # Do not perform function call in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable
99+
"B904", # Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
100+
# D rules (pydocstyle)
101+
"D101", # Missing docstring in public class
102+
"D102", # Missing docstring in public method
103+
"D103", # Missing docstring in public function
104+
"D107", # Missing docstring in `__init__`,
105+
"D401", # First line of docstring should be in imperative mood: "Loads the vocabulary from the specified path."
106+
"D404", # First word of the docstring should not be "This"
107+
"D417", # Missing argument descriptions in the docstring
108+
# E rules (pycodestyle)
109+
"E731", # Do not assign a `lambda` expression, use a `def`
110+
"E741", # Ambiguous variable name
111+
# ERA rules (flake8-eradicate)
112+
"ERA001", # Found commented-out code
113+
# F rules (Pyflakes)
114+
"F821", # Undefined name
115+
# FIX rules (flake8-fixme)
116+
"FIX002", # Line contains TODO, consider resolving the issue
117+
# N rules (pep8-naming)
118+
"N802", # Function name should be lowercase,
119+
# NPY rules (numpy-specific rules)
120+
"NPY002", # Replace legacy
121+
# PD rules (pandas-vet)
122+
"PD002", # `inplace=True` should be avoided; it has inconsistent behavior
123+
"PD003", # `.isna` is preferred to `.isnull`; functionality is equivalent
124+
"PD011", # Use `.to_numpy()` instead of `.values`
125+
"PD015", # Use `.merge` method instead of `pd.merge` function
126+
# PT rules (flake8-pytest-style)
127+
"PT009", # Use a regular `assert` instead of unittest-style `assertEqual`
128+
"PT018", # Assertion should be broken down into multiple parts
129+
"PT027", # Use `pytest.raises` instead of unittest-style `assertRaisesRegex`
130+
# RET rules (flake8-return)
131+
"RET504", # Unnecessary assignment to variable before `return` statement
132+
"RET505", # Unnecessary `elif` after `return` statement
133+
# SIM rules (flake8-simplify)
134+
"SIM101", # Multiple `isinstance` calls for `maybe_collection`, merge into a single call
135+
"SIM102", # Use a single `if` statement instead of nested `if` statements
136+
"SIM103", # Return the condition directly
137+
"SIM105", # Use `contextlib.suppress(...)` instead of `try`-`except`-`pass`
138+
"SIM117", # Use a single `with` statement with multiple contexts instead of nested `with` statements
139+
"SIM211", # Use `not ...` instead of `False if ... else True`
140+
# UP rules (pyupgrade)
141+
"UP008", # Use `super()` instead of `super(__class__, self)`
142+
"UP028", # Replace `yield` over `for` loop with `yield from`
143+
"UP031", # Use format specifiers instead of percent format
144+
]
145+
146+
147+
[tool.ruff.lint.per-file-ignores]
148+
"__init__.py" = ["F401"]

0 commit comments

Comments
 (0)