Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: check files key in track-level config #435

Merged
merged 44 commits into from
Oct 13, 2021

Conversation

bobtfish
Copy link
Contributor

@bobtfish bobtfish commented Oct 5, 2021

Addresses some of #249

Implements the following rules:

  • The "files" key is optional
  • The "files" value must be an object
  • The "files.solution" key is optional
  • The "files.solution" value must be an array
  • The "files.solution" values must be valid patterns⁴
  • The "files.solution" values must not have duplicates
  • The "files.test" key is optional
  • The "files.test" value must be an array
  • The "files.test" values must be valid patterns⁴
  • The "files.test" values must not have duplicates
  • The "files.example" key is optional
  • The "files.example" value must be an array
  • The "files.example" values must be valid patterns⁴
  • The "files.example" values must not have duplicates
  • The "files.exemplar" key is optional
  • The "files.exemplar" value must be an array
  • The "files.exemplar" values must be valid patterns⁴
  • The "files.exemplar" values must not have duplicates
  • The "files.editor" key is optional
  • The "files.editor" value must be an array
  • The "files.editor" values must be valid patterns⁴
  • The "files.editor" values must not have duplicates
  • Patterns can only be listed in either the "files.solution", "files.test", "files.example, "files.exemplar or "files.editor array (no overlap)

Copy link
Member

@ErikSchierboom ErikSchierboom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I'll leave the Nim code review to @ee7 .

src/lint/validators.nim Outdated Show resolved Hide resolved
src/lint/validators.nim Outdated Show resolved Hide resolved
tests/test_lint.nim Outdated Show resolved Hide resolved
@ErikSchierboom
Copy link
Member

@bobtfish Great!

ee7 added 19 commits October 7, 2021 16:30
This is more consistent with the test layout in the `isFilesPattern`
suite, and elsewhere in this file.
Personal taste, but this makes it easier to see that the pattern is
identical in each pair of lines, and we've tended to use `.len`
elsewhere.
Before:
  no placeholder
  with placeholder
  multiple placeholders

After:
  no placeholder
  one placeholder
  multiple placeholders
Previously, an IndexDefect was raised for an input string that ends with
the % character.
Let's put both these variables close to the `isString` proc that uses
them.
Appease `nimpretty`.
I think this reads more naturally, and we've tended to use this style
elsewhere.
This makes it obvious that `filesPatterns` isn't used elsewhere.
This makes the name of this variable more consistent with the code in
`isFilesPattern`:

    for ph in extractPlaceholders(s):
      if ph notin filesPatterns:
        result = false
The Nim compiler doesn't optimize the previous pattern.

The recommended ways to write it are these:

    foo.add bar
    foo &= bar
This makes it obvious that we don't mutate `c`.
This is more consistent with the name of the parameter in
`isFilesPattern`, and our code elsewhere.
@ee7
Copy link
Member

ee7 commented Oct 7, 2021

Again, thanks for working on this. I've done a first pass review - looking good.

I again took the liberty of just pushing the commits - please yell at me if you hate anything, or have any questions. Most notably, a string that ended in % would previously raise an IndexDefect.

There's a few more things I want to have before merging (in particular: a few more test cases, and a warning for bad placeholder usage would indeed be nice) but I think it's pretty close.

@ee7 ee7 changed the title Implement the config.json files section linting. lint: check files key in track-level config Oct 8, 2021
This was used neither in the configlet codebase, nor the tests.
Probably more readable.
I don't have a strong preference for this indentation style, but it's
what we've used elsewhere.
It was a little confusing that passing `isRequired = false` to
`hasObject` did nothing, because we checked `hasKey` twice.

But the problem is that the existing `hasX` design is a bit of a mess,
or at least the proc names. I don't love that a proc named `hasObject`
returns true when `isRequired = false` is passed.

Let's just do it this way for now - I found it little clearer.
Eventually, all this `hasX` code might be refactored.
This makes it more obvious that this func was only used during the
tests.

After the Nim 1.6 release we'll be able to test procs in other modules
without exporting them.
This test case used 3 placeholder characters, not 2.
@bobtfish
Copy link
Contributor Author

bobtfish commented Oct 8, 2021

hey @ee7 thanks for brushing up my code.

Are you going to take this over the line, or would you like me to add the warning? (I think you added the extra tests already, right?)

This reverts commit 6df6fe6.

Oops. It does need to be like this. Otherwise, when the optional `files`
key is missing, `configlet lint` incorrectly prints this:

    The `files` key is missing:
    ./config.json
This is a very basic check, but at least it catches something like

    %{snake_slug.foo

Currently, there is only one track with multiple placeholders.
And the (unlikely) use of 3 placeholders.
@ee7
Copy link
Member

ee7 commented Oct 12, 2021

thanks for brushing up my code.

No problem.

Are you going to take this over the line

@bobtfish Yes - thanks. I'll just add a very basic warning and then I'll merge.

I've also like to add more rules about file patterns to the spec, but we should handle that later.

Note that the string is still set at compile-time.

The func is a bit long - oh well.
This better communicates that `extractPlaceholders` isn't printing error
messages, so we don't need to iterate over every placeholder.
@ee7
Copy link
Member

ee7 commented Oct 12, 2021

At the time of writing, this PR produces the following diff to the output of configlet lint, per-track:

ballerina

+A `files.exemplar` value is `.meta/reference/%{snake_slug}.bal`, which is not a unique `files` entry:
+./config.json
+

d

+A `files.test` value is `source/%{snake_slug}.d`, which is not a unique `files` entry:
+./config.json
+
+Configlet detected at least one problem.
+For more information on resolving the problems, please see the documentation:
+https://github.com/exercism/docs/blob/main/building/configlet/lint.md

fortran

+A `files.exemplar` value is `%{snake_slug}.f90`, which is not a unique `files` entry:
+./config.json
+
+Configlet detected at least one problem.
+For more information on resolving the problems, please see the documentation:
+https://github.com/exercism/docs/blob/main/building/configlet/lint.md

groovy

+A `files.exemplar` value is `.meta/src/reference/groovy/%{pascal_slug}.groovy`, which is not a unique `files` entry:
+./config.json
+
+Configlet detected at least one problem.
+For more information on resolving the problems, please see the documentation:
+https://github.com/exercism/docs/blob/main/building/configlet/lint.md

java

+A `files.exemplar` value is `.meta/src/reference/java/%{pascal_slug}.java`, which is not a unique `files` entry:
+./config.json
+
+Configlet detected at least one problem.
+For more information on resolving the problems, please see the documentation:
+https://github.com/exercism/docs/blob/main/building/configlet/lint.md

pharo-smalltalk

+A `files.exemplar` value is `.meta/solution/%{pascal_slug}.class.st`, which is not a unique `files` entry:
+./config.json
+
+Configlet detected at least one problem.
+For more information on resolving the problems, please see the documentation:
+https://github.com/exercism/docs/blob/main/building/configlet/lint.md

plsql

+A `files.test` value is `ut_%{snake_slug}#.plsql`, which is not a unique `files` entry:
+./config.json
+
+Configlet detected at least one problem.
+For more information on resolving the problems, please see the documentation:
+https://github.com/exercism/docs/blob/main/building/configlet/lint.md

vimscript

+A `files.exemplar` value is `example.vim`, which is not a unique `files` entry:
+./config.json
+
+Configlet detected at least one problem.
+For more information on resolving the problems, please see the documentation:
+https://github.com/exercism/docs/blob/main/building/configlet/lint.md

This makes the code use the terminology from the docs:

4. Valid `files` pattern: A non-blank string¹ that specifies a location
   of a file used in an exercise, relative to the exercise's directory.
   A pattern may use one of the following placeholders:
   - `%{kebab_slug}`: the `kebab-case` exercise slug (e.g. `bit-manipulation`)
   - `%{snake_slug}`: the `snake_case` exercise slug (e.g. `bit_manipulation`)
   - `%{camel_slug}`: the `camelCase` exercise slug (e.g. `bitManipulation`)
   - `%{pascal_slug}`: the `PascalCase` exercise slug (e.g. `BitManipulation`)
"valid files pattern" sounds like it could be missing a possessive
apostrophe.

Let's refer to a single string as either a
  `files` pattern
or a
  file pattern

The latter reads better here, since the key name is already mentioned.
@ee7 ee7 merged commit 2a6bfa9 into exercism:main Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants