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

#2025: Add check to ensure files end in .json #2026

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

davenewham
Copy link
Contributor

@davenewham davenewham commented Dec 30, 2022

This should help prevent errors from manually editing within the github browser :^)

Closes #2025

@mal-tee mal-tee self-assigned this Dec 31, 2022
Copy link
Member

@mal-tee mal-tee left a comment

Choose a reason for hiding this comment

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

Thank you very much! Funny that I did the same mistake over a year ago.. :D

src/checks/index.ts Outdated Show resolved Hide resolved
src/checks/index.ts Outdated Show resolved Hide resolved
Comment on lines +16 to +17
message: `File \`${filename}\` should end in .json. Please rename the file.`,
location: { start: { line: 1 } },
Copy link
Member

@mal-tee mal-tee Dec 31, 2022

Choose a reason for hiding this comment

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

This won't make much sense as a suggestion from the reviewbot, but afaik there is no way for a code suggestion to rename a file in GH. @baltpeter do you have an opinion on this?

Copy link
Member

Choose a reason for hiding this comment

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

afaik there is no way for a code suggestion to rename a file in GH.

No, there isn't. I agree, this should just be a comment without a suggestion.

@mal-tee mal-tee added the test label Dec 31, 2022
Copy link
Member

@baltpeter baltpeter left a comment

Choose a reason for hiding this comment

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

Thank you! (And sorry for taking so long with the review.)

Comment on lines +35 to +39
genericlint: {
checks: await importChecks('generic'),
url: 'https://github.com/datenanfragen/data/blob/master/src/checks/generic',
path_filter: (path: string) => path.startsWith('companies/') || path.startsWith('company-packs/') || path.startsWith('supervisory-authorities/') || path.startsWith('suggested-companies/'),
},
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to establish another check type for this? The suggested companies are deprecated (and can actually be removed from the repo now). If we made this a record check, we would indeed miss the company packs, but I feel like this is less critical for them (a missing company pack is a lot more obvious than a missing company). What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Actually: If we decide, we only need this for records, do we still need the additional check at all? I think match-filename-slug should cover this already in that case.

@@ -37,7 +37,7 @@ const validate = async (dir: string) => {
const check_results: RdjsonLine[] = [];

const linters = await _linters();
const files = glob.sync(`${dir}/*.json`);
const files = glob.sync(`${dir}/*`);
Copy link
Member

Choose a reason for hiding this comment

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

I worried this might create a problem on systems that like to automatically place files in directories (Thumbs.db, .DS_Store etc.).

We should ignore everything in the .gitignore in this matcher. Unfortunately, our glob library doesn't support that as far as I can see. It might be worth switching to something like https://github.com/sindresorhus/globby.

@@ -0,0 +1,22 @@
import { basename, extname } from 'path';
import { exit } from 'process';
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a stray import.

const filename = basename(ctx.file_path);
const file_extension = extname(ctx.file_path)

if (file_extension != ".json")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (file_extension != ".json")
if (file_extension !== ".json")

Comment on lines +16 to +17
message: `File \`${filename}\` should end in .json. Please rename the file.`,
location: { start: { line: 1 } },
Copy link
Member

Choose a reason for hiding this comment

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

afaik there is no way for a code suggestion to rename a file in GH.

No, there isn't. I agree, this should just be a comment without a suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

Test for missing or wrong extensions
3 participants