Commit Graph

30 Commits

Author SHA1 Message Date
Nic Cope 0c7b1eb549 Bump golangci-lint, copy config from c/c
This copies the latest config from c/c and addresses all the linter
errors that config produces.

Signed-off-by: Nic Cope <nicc@rk0n.org>
2024-02-20 03:45:27 -08:00
Philippe Scorsolini b82c293947
Merge pull request #553 from lsviben/lintable 2023-09-22 12:49:57 +02:00
lsviben 3edf846d8f
add docs
Signed-off-by: lsviben <sviben.lovro@gmail.com>
2023-09-22 11:25:03 +02:00
lsviben a6045dd880
introduce Lintable
Signed-off-by: lsviben <sviben.lovro@gmail.com>
2023-09-20 14:55:48 +02:00
Philippe Scorsolini 6cb0b49702
refactor: switch to side effect free check
Signed-off-by: Philippe Scorsolini <p.scorsolini@gmail.com>
2023-09-19 12:53:41 +02:00
Philippe Scorsolini 7a082cc2b6
fix(package parser): only drop fully commented files
Signed-off-by: Philippe Scorsolini <p.scorsolini@gmail.com>
2023-09-15 18:12:41 +02:00
Muvaffak Onus 4cba0090d9 pkg.parser: add the ability to parse manifests with comments
Signed-off-by: Muvaffak Onus <me@muvaf.com>
2023-08-08 17:55:49 +03:00
Philippe Scorsolini 511b39fa56
chore: address issues reported by revive
Signed-off-by: Philippe Scorsolini <p.scorsolini@gmail.com>
2023-04-05 12:03:27 +02:00
Philippe Scorsolini d95d8e0cca tests: move FuzzParse to separate file
Co-authored-by: Lovro Sviben <46844730+lsviben@users.noreply.github.com>
Signed-off-by: Philippe Scorsolini <p.scorsolini@gmail.com>
2023-03-16 22:26:08 +01:00
Philippe Scorsolini 5a5939990b
tests(fuzz): add FuzzParse test case
Signed-off-by: Philippe Scorsolini <p.scorsolini@gmail.com>
2023-03-13 11:26:30 +01:00
Nic Cope f0fcbc0af5 Update linter config to match c/c
This repo is a little out of date relative to our latest linting
practices.

Signed-off-by: Nic Cope <nicc@rk0n.org>
2023-01-25 10:32:46 -08:00
Aditya Sharma cd68866501 Fix lints
Signed-off-by: Aditya Sharma <git@adi.run>
2022-07-21 22:01:32 -07:00
Aditya Sharma 1deb753676 s/interface{}/any/g
Signed-off-by: Aditya Sharma <git@adi.run>
2022-07-21 21:46:18 -07:00
Muvaffak Onus 90b7988df4
parser.linter: use strings.Join instead of strings.TrimSuffix to make the flow simpler
Signed-off-by: Muvaffak Onus <me@muvaf.com>
2022-03-09 11:21:56 +03:00
Muvaffak Onus 155dc9d659
package.parser: make Or linter work with arbitrary number of linters instead of only two
Signed-off-by: Muvaffak Onus <me@muvaf.com>
2022-03-07 17:00:48 +03:00
hasheddan f3ea898989
Use Wrapf for annotating parser errors
Updates error annotation formatting to use errors.Wrapf.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2021-10-29 17:00:55 -04:00
hasheddan cc6f044e79
Only attempt object scheme parsing if object is not registered in meta
Updates the package parsing logic to only attempt decoding with the
object scheme in the case that the error from decoding in the meta
scheme is due to the GVK not being registered. This does not change the
definition of a valid package, but does result in more informative
errors being returned when a package is invalid due to a malformed meta
type.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2021-10-29 15:51:06 -04:00
Nic Cope af4e148a11 Replace github.com/pkg/errors with our own pkg/errors.
Signed-off-by: Nic Cope <negz@rk0n.org>
2021-09-09 07:50:57 +00:00
hasheddan d76ee9b025
Ignore empty YAML documents in parser
If a document contains only whitespace and we are not able to decode it
into one of the supported schemas, we ignore it and continue. We want to
avoid skipping a type that does not have a registered schema so that we
do not silently ignore errors when package building, but we consider it
safe to assume that a YAML document with no content is safe to skip.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2021-06-09 10:56:24 -05:00
hasheddan a37f37a745
Write YAML document terminator on file end
YAML supports a document terminator (...) when reading files in a
stream. This allows for the reader to indicate that the current document
has ended without indicating that the stream is finished. Anything after
the document terminator is ignored by the consumer. Therefore, we write
the terminator at the end of a read file, then immediately follow with a
YAML document separator (---), which is mandatory according to the YAML
spec when using document terminators.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2021-06-09 10:49:36 -05:00
hasheddan 2d0e327a89
Add SkipEmpty FilterFn
The FsReadCloser claimed to implictly skip empty files, but this was
only true when the final file to be read was empty. This updates to add
a SkipEmpty option that will filter out empty files before even
attempting to read file contents.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-12-08 16:16:48 -06:00
hasheddan 96e0fce629
Make FsReadCloser an AnnotatedReader
Adds the annotate method to FsReadCloser so that it can provide
additional context to parser about most recently read data in the event
of an error.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-12-08 16:16:20 -06:00
hasheddan 28b5c76222
Add annotated reader interface for parser
An annotated reader supplies the package parser with additional context
about data that was read. The parser does not require a backend reader
to supply annotation information, but will check to see if the reader
implements the interface and will invoke it if an error is encountered.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-12-08 16:15:57 -06:00
hasheddan a521e1178f
Note that FsReadCloser does not follow symlinks
Adds note to NewFsReadCloser to indicate that symbolic links will not be
honored when walking the filesystem.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-11-19 20:09:25 -06:00
hasheddan 9918fd7907
Move common linter functionality to parser pkg
Downstream consumers may implement their own linter functions, but the
core linter loop can be generalized, as well as helper functions such as
Or.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-10-05 08:02:55 -05:00
hasheddan 94f307fb2a
Rename DefaultParser to PackageParser
DefaultParser is not descriptive of the Parser implementation's purpose.
PackageParser indicates the this parser is meant for parsing packages.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-10-03 09:56:13 -05:00
Nic Cope 0a1513a2de Bump build package for new golangci-lint
Address a few (mostly) false positives introduced by the new linter.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-09-26 15:35:20 -07:00
hasheddan 0920efd331
Accept ObjectCreaterTyper interface instead of runtime.Scheme directly
Because the parser eventually passes a runtime.Creater and runtime.Typer
to the underlying serializer, we only require that the passed schemes
implement those interfaces, rather than require that they be
*runtime.Scheme explicitly.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-09-06 17:08:31 -05:00
hasheddan 49da505413
Add package parser
Adds a package parser and a variety of backends that reads from a YAML
stream, accepting objects that are either part of the meta or object
runtime.Scheme and returning them as a Package.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-09-04 19:59:50 -05:00
hasheddan 76c547909e
Add FsReadCloser to implement io.ReadCloser for a filesystem
Implements io.ReadCloser for afero.Fs to allow passing it to a parser
that accepts an io.ReadCloser and reads from it.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-09-04 19:59:49 -05:00