Skip to content

Commit 6981fa9

Browse files
authored
Readme no docker & allow using platform default version (#66)
* readme about docker-less usage & tidy config file * change punctuation a bit * proofreading example * add example of multi-lined CLI args * more proofreading * add macos-latest details * final proofreading * update pylintrc; allow version to be blank * revert docker's default version * pleasing pylint * force operator resolution order
1 parent c825315 commit 6981fa9

File tree

3 files changed

+67
-60
lines changed

3 files changed

+67
-60
lines changed

.pylintrc

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ confidence=
5252
# no Warning level messages displayed, use"--disable=all --enable=classes
5353
# --disable=W"
5454
# disable=print-statement,parameter-unpacking,unpacking-in-except,backtick,long-suffix,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,bad-whitespace
55-
disable=invalid-sequence-index,anomalous-backslash-in-string,print-statement,too-few-public-methods,consider-using-f-string,subprocess-run-check
55+
disable=invalid-sequence-index,anomalous-backslash-in-string,too-few-public-methods,consider-using-f-string,subprocess-run-check
5656

5757
# Enable the message, report, category or checker with the given id(s). You can
5858
# either give multiple identifier separated by comma (,) or put this option
@@ -222,12 +222,6 @@ max-line-length=88
222222
# Maximum number of lines in a module
223223
max-module-lines=1000
224224

225-
# List of optional constructs for which whitespace checking is disabled. `dict-
226-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
227-
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
228-
# `empty-line` allows space-only lines.
229-
no-space-check=trailing-comma,dict-separator
230-
231225
# Allow the body of a class to be on the same line as the declaration if body
232226
# contains single statement.
233227
single-line-class-stmt=no
@@ -254,48 +248,29 @@ min-similarity-lines=4
254248

255249
[BASIC]
256250

257-
# Naming hint for argument names
258-
argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
259-
260251
# Regular expression matching correct argument names
261252
argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
262253

263-
# Naming hint for attribute names
264-
attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
265-
266254
# Regular expression matching correct attribute names
267255
attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
268256

269257
# Bad variable names which should always be refused, separated by a comma
270258
bad-names=foo,bar,baz,toto,tutu,tata
271259

272-
# Naming hint for class attribute names
273-
class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
274-
275260
# Regular expression matching correct class attribute names
276261
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
277262

278-
# Naming hint for class names
279-
# class-name-hint=[A-Z_][a-zA-Z0-9]+$
280-
class-name-hint=[A-Z_][a-zA-Z0-9_]+$
281-
282263
# Regular expression matching correct class names
283264
# class-rgx=[A-Z_][a-zA-Z0-9]+$
284265
class-rgx=[A-Z_][a-zA-Z0-9_]+$
285266

286-
# Naming hint for constant names
287-
const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$
288-
289267
# Regular expression matching correct constant names
290268
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
291269

292270
# Minimum line length for functions/classes that require docstrings, shorter
293271
# ones are exempt.
294272
docstring-min-length=-1
295273

296-
# Naming hint for function names
297-
function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
298-
299274
# Regular expression matching correct function names
300275
function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
301276

@@ -306,21 +281,12 @@ good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_
306281
# Include a hint for the correct naming format with invalid-name
307282
include-naming-hint=no
308283

309-
# Naming hint for inline iteration names
310-
inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$
311-
312284
# Regular expression matching correct inline iteration names
313285
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
314286

315-
# Naming hint for method names
316-
method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
317-
318287
# Regular expression matching correct method names
319288
method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
320289

321-
# Naming hint for module names
322-
module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
323-
324290
# Regular expression matching correct module names
325291
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
326292

@@ -336,9 +302,6 @@ no-docstring-rgx=^_
336302
# to this list to register other decorators that produce valid properties.
337303
property-classes=abc.abstractproperty
338304

339-
# Naming hint for variable names
340-
variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
341-
342305
# Regular expression matching correct variable names
343306
variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
344307

README.md

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ jobs:
6666

6767
- **Description**: Comma-separated list of globs with optional '-' prefix. Globs are processed in order of appearance in the list. Globs without '-' prefix add checks with matching names to the set, globs with the '-' prefix remove checks with matching names from the set of enabled checks. This option's value is appended to the value of the 'Checks' option in a .clang-tidy file (if any).
6868
- It is possible to disable clang-tidy entirely by setting this option to '-\*'. This allows using only clang-format to lint your source files.
69+
- It is also possible to rely solely on a .clang-tidy config file by specifying this option as a blank string ('').
6970
- Default: 'boost-\*,bugprone-\*,performance-\*,readability-\*,portability-\*,modernize-\*,clang-analyzer-\*,cppcoreguidelines-\*'
7071

7172
#### `repo-root`
@@ -76,6 +77,7 @@ jobs:
7677
#### `version`
7778

7879
- **Description**: The desired version of the [clang-tools](https://hub.docker.com/r/xianpengshen/clang-tools) to use. Accepted options are strings which can be 14, 13, 12, 11, 10, 9, or 8.
80+
- Set this option to a blank string ('') to use the platform's default installed version.
7981
- Default: '10'
8082

8183
#### `verbosity`
@@ -132,11 +134,25 @@ jobs:
132134

133135
This action creates 1 output variable named `checks-failed`. Even if the linting checks fail for source files this action will still pass, but users' CI workflows can use this action's output to exit the workflow early if that is desired.
134136

135-
## Using a Windows-based runner
137+
## Running without the docker container
136138

137-
This action can only be run on a runner using the Ubuntu Operating System. However, this action's source code (essentially a python package) can be used on a runner using the Windows Operating System.
139+
Some Continuous Integration environments require access to non-default compilers
140+
and/or non-standard libraries. To do this properly, the docker container should
141+
not be used due to it's isolated file system. Instead, you should use this action's
142+
python source code as an installed python package (see below).
138143

139-
Note: MacOS-based runners have not been tested, but the same approach applies.
144+
### Using the python source code
145+
146+
This action was originally designed to only be used on a runner with the Ubuntu
147+
Operating System. However, this action's source code (essentially a python package)
148+
can be used on any runner using the Windows, Ubuntu, or possibly even MacOS (untested)
149+
virtual environments.
150+
151+
Note, some runners already ship with clang-format and/or clang-tidy. As of this writing, the following versions of clang-format and clang-tidy are already available:
152+
153+
- `ubuntu-latest` ships with v10, v11, and v12. [More details](https://github.com/actions/virtual-environments/blob/ubuntu20/20220508.1/images/linux/Ubuntu2004-Readme.md).
154+
- `windows-latest` ships with v13. [More details](https://github.com/actions/virtual-environments/blob/win22/20220511.2/images/win/Windows2022-Readme.md).
155+
- `macos-latest` ships with v13. [More details](https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md).
140156

141157
This example makes use of another action
142158
([KyleMayes/install-llvm-action](https://github.com/KyleMayes/install-llvm-action))
@@ -156,22 +172,27 @@ jobs:
156172
- uses: actions/checkout@v3
157173
- uses: actions/setup-python@v3
158174

175+
# this step can be skipped if the desired
176+
# version already comes with the runner's OS
159177
- name: Install clang-tools
160178
uses: KyleMayes/install-llvm-action@v1
161179
with:
162-
# v12 is the recommended minimum for the Visual Studio compiler
163-
version: 12
164-
# specifying an install path is required because
165-
# Windows runners already have a certain version of LLVM installed
180+
# v12 is the recommended minimum for the Visual Studio compiler (on Windows)
181+
version: 14
182+
# specifying an install path is required (on Windows) because installing
183+
# multiple versions on Windows runners needs non-default install paths.
166184
directory: ${{ runner.temp }}/llvm
167185

168186
- name: Install linter python package
169187
run: python3 -m pip install git+https://github.com/cpp-linter/cpp-linter-action@v1
170188

171189
- name: run linter as a python package
172190
id: linter
173-
# pass the installed path to the '--version' argument
174-
run: cpp-linter --version=${{ runner.temp }}/llvm
191+
# pass the installed path to the '--version' argument (Windows only).
192+
# Any other OS-based runners only take the version number.
193+
# Example. run: cpp-linter --version=14
194+
# Omit the version option if using the default version available in the OS.
195+
run: cpp-linter --version=${{ runner.temp }}/llvm
175196

176197
- name: Fail fast?!
177198
if: steps.linter.outputs.checks-failed > 0
@@ -180,7 +201,31 @@ jobs:
180201
# run: exit 1
181202
```
182203

183-
All input options listed above are specified by pre-pending a `--`. You can also install this repo locally and run `cpp-linter -h` for more detail.
204+
All input options listed above are specified by pre-pending a `--`. You can also install this repo locally and run `cpp-linter -h` for more detail. For example:
205+
206+
```yaml
207+
- uses: cpp-linter/cpp-linter-action@v1
208+
with:
209+
style: file
210+
tidy-checks: '-*'
211+
files-changed-only: false
212+
ignore: 'dist/third-party-lib'
213+
```
214+
215+
is equivalent to
216+
217+
```yaml
218+
- name: Install linter python package
219+
run: python3 -m pip install git+https://github.com/cpp-linter/cpp-linter-action@v1
220+
221+
- name: run linter as a python package
222+
run: |
223+
cpp-linter \
224+
--style=file \
225+
--tidy-checks='-*' \
226+
--files-changed-only=false \
227+
--ignore='dist/third-party-lib'
228+
```
184229
185230
## Example
186231

cpp_linter/run.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
cli_arg_parser.add_argument(
8383
"-V",
8484
"--version",
85-
default="10",
85+
default="",
8686
help="The desired version of the clang tools to use. Accepted options are strings "
8787
"which can be 8, 9, 10, 11, 12, 13, 14. Defaults to %(default)s. On Windows, this "
8888
"can also be a path to the install location of LLVM",
@@ -403,18 +403,17 @@ def run_clang_tidy(
403403
# clear the clang-tidy output file and exit function
404404
with open("clang_tidy_report.txt", "wb") as f_out:
405405
return
406-
cmds = [f"clang-tidy-{version}"]
407-
if sys.platform.startswith("win32"):
408-
cmds = ["clang-tidy"]
409-
if os.path.exists(version + os.sep + "bin"):
410-
cmds = [f"{version}\\bin\\clang-tidy.exe"]
411-
elif not version.isdigit():
406+
cmds = [
407+
"clang-tidy" + ("" if not version else f"-{version}"),
408+
"--export-fixes=clang_tidy_output.yml",
409+
]
410+
if sys.platform.startswith("win32") and os.path.exists(version + os.sep + "bin"):
411+
cmds[0] = f"{version + os.sep}bin\\clang-tidy.exe"
412+
elif not sys.platform.startswith("win32") and not version.isdigit():
412413
logger.warning("ignoring invalid version number %s.", version)
413-
cmds = ["clang-tidy"]
414+
cmds[0] = "clang-tidy"
414415
if checks:
415416
cmds.append(f"-checks={checks}")
416-
cmds.append("--export-fixes=clang_tidy_output.yml")
417-
# cmds.append(f"--format-style={style}")
418417
if database:
419418
cmds.append("-p")
420419
if RUNNER_WORKSPACE:
@@ -459,7 +458,7 @@ def run_clang_format(
459458
"""
460459
is_on_windows = sys.platform.startswith("win32")
461460
cmds = [
462-
"clang-format" + ("" if is_on_windows else f"-{version}"),
461+
"clang-format" + ("" if not version else f"-{version}"),
463462
f"-style={style}",
464463
"--output-replacements-xml",
465464
]
@@ -614,7 +613,7 @@ def post_diff_comments(base_url: str, user_id: int) -> bool:
614613
if (
615614
int(comment["user"]["id"]) == user_id
616615
and comment["line"] == body["line"]
617-
and comment["path"] == payload[i]["path"]
616+
and comment["path"] == body["path"]
618617
):
619618
already_posted = True
620619
if comment["body"] != body["body"]:

0 commit comments

Comments
 (0)