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

Correcting go.mod and go.sum to generated files instead of AMPL. #4306

Merged
merged 1 commit into from
Nov 1, 2018
Merged

Correcting go.mod and go.sum to generated files instead of AMPL. #4306

merged 1 commit into from
Nov 1, 2018

Conversation

leighlondon
Copy link
Contributor

Correcting go.mod and go.sum to Go.

Description

Go's new "modules" feature uses some additional filenames - go.mod and go.sum. The go.mod file is misclassified as "AMPL" due to fallthrough in the heuristics.

I've added a new go.mod sample file and adjusted the heuristics to try get these module files classified as Go.

Checklist:

  • I am associating a language with a new file extension.

  • I am adding a new language.

  • I am fixing a misclassified language

    • I have included a new sample for the misclassified language:
      • Sample source(s):
        • go.mod example added
      • Sample license(s):
    • I have included a change to the heuristics to distinguish my language from others using the same extension.
  • I am changing the source of a syntax highlighting grammar

  • I am updating a grammar submodule

  • I am adding new or changing current functionality

    • I have added or updated the tests for the new or changed functionality.

@lildude
Copy link
Member

lildude commented Oct 27, 2018

To save you time: we don't need a heuristic for explicitly named files. The analysis will never get to the heuristic 😄

@leighlondon
Copy link
Contributor Author

Oh, even easier then!

Copy link
Contributor

@pchaigno pchaigno left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

I've left two comments to address inline 👇

samples/Go/go.mod Outdated Show resolved Hide resolved
lib/linguist/heuristics.yml Outdated Show resolved Hide resolved
samples/Go/go.sum Outdated Show resolved Hide resolved
samples/Go/go.mod Outdated Show resolved Hide resolved
@leighlondon
Copy link
Contributor Author

Adding the samples broke the tests so I've moved them to the right location now.

@leighlondon
Copy link
Contributor Author

@pchaigno is there a way to "unlanguage" a certain file then? If it's not necessarily Go (since it's not), is there a way for us to say that it's not anything else as well?

@pchaigno
Copy link
Contributor

is there a way to "unlanguage" a certain file then?

There's not. It's a known limitation of Linguist which we've discussed several times, but haven't found the time to address.

Maybe we can address this another way: Are these files generated or are they written by humans? Are go.mod files closer to some other language? It looks like they have structure (require, module, etc.); how are they processed?

@leighlondon
Copy link
Contributor Author

They're "generated" files, and rarely (but not never) edited by humans - specifically, they're generated by the Go binary, using go mod tidy and so on. There's some info with some details about the mod file in the golang/go wiki but not specifically about the parsing of it, which would take a bit of a dive through the code to write up a format for a language bundle.

The closest analogy is probably to JavaScript's package.json and package-lock.json - dependency metadata which is linked specifically to the language (though go.mod isn't JSON, unfortunately, and go.sum is just a list of cryptographic hashes).

I had a look at the code in generated.rb and it says that they would be "suppressed in diffs" if generated, is that specifically for things like GitHub pull requests?

@pchaigno
Copy link
Contributor

They're "generated" files, and rarely (but not never) edited by humans - specifically, they're generated by the Go binary, using go mod tidy and so on.

Maybe we should add them to generated.rb? go.mod would still be recognized as AMPL, but at least it wouldn't count in language statistics. What do you think?

I had a look at the code in generated.rb and it says that they would be "suppressed in diffs" if generated, is that specifically for things like GitHub pull requests?

Yes, it means they won't show up in diffs across GitHub.com (PRs, branch comparisons, etc.). That won't affect the git diff command output if that was your concern.

@leighlondon
Copy link
Contributor Author

The main (only?) thing I was trying to do was just to stop repos and statistics showing AMPL as a language in that upper bar.

I think switching to generated would cover that from what you've mentioned, which would be great - I should be able to make those changes and push a new update.

@leighlondon
Copy link
Contributor Author

Do you want the explicit "filenames" section removed from the language specification? From my understanding that is not required if it's generated?

The samples are used in the tests so I've left them in (but can remove them if needed).

Thanks for the help! 👍

@pchaigno
Copy link
Contributor

Do you want the explicit "filenames" section removed from the language specification? From my understanding that is not required if it's generated?

I'd rather we remove them.

The samples are used in the tests so I've left them in (but can remove them if needed).

If we remove the filenames in languages.yml, we'll also need to remove the samples. They're not used in the tests anyway since you don't need to read the content of files, only to check their name.

@leighlondon leighlondon changed the title Correcting go.mod and go.sum to Go. Correcting go.mod and go.sum to generated files instead of AMPL. Oct 28, 2018
@leighlondon
Copy link
Contributor Author

Changes were made, but the Travis build is still going at 30 minutes... checking all the builds shows that Travis thinks they all passed (Done. Your build exited with 0.) but it won't end. As far as I can tell it might be a Travis error, but I'm not sure, I didn't exactly change a lot.

@pchaigno
Copy link
Contributor

Looks like a bug in Travis CI (maybe due to the Daylight saving time change in Europe). I tried to restart the builds but there seems to be the same problem again. I'll try again this evening or tomorrow if it doesn't resolve itself in the meantime.

@leighlondon
Copy link
Contributor Author

Finally passed now! 🎉

Copy link
Contributor

@pchaigno pchaigno left a comment

Choose a reason for hiding this comment

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

LGTM!

@leighlondon Thanks for your contribution and your patience!

@leighlondon
Copy link
Contributor Author

Thanks for the help and being so patient with me @pchaigno 😄

Copy link
Member

@lildude lildude left a comment

Choose a reason for hiding this comment

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

LGTM Thanks for the contribution and welcome to Linguist.

@lildude lildude merged commit ba0c5e9 into github-linguist:master Nov 1, 2018
@myitcv
Copy link

myitcv commented Nov 19, 2018

@leighlondon @pchaigno - changes to go.mod and go.sum files represent something that should be reviewed as part of a PR, so treating them as generated files is not correct to my mind.

The fact that go.mod largely represents the result of a tool having modified the file is a function of good tooling as opposed to the file by definition being generated.

Changes to go.sum are of interest because it highlights transitive dependencies being added to/removed from your module.

@mvdan
Copy link

mvdan commented Nov 19, 2018

I very much agree with @myitcv - even if one should never edit go.sum manually, both files are very important during reviews. And go.mod has its own format precisely to make it readable and writable by humans.

@pchaigno
Copy link
Contributor

@lildude Should we revert this? How did we handle this kind of issues in the past?

@myitcv
Copy link

myitcv commented Nov 19, 2018

@lildude @pchaigno I've pushed up #4333 in case you want to move forward instead of reverting.

@github-linguist github-linguist deleted a comment from thetruth97 Nov 19, 2018
@leighlondon
Copy link
Contributor Author

Could be reverted or the original suggestion could be applied to update heuristics by filename match- all up to you guys @pchaigno and @lildude. Either way is fine. :)

@lildude
Copy link
Member

lildude commented Nov 20, 2018

@lildude Should we revert this? How did we handle this kind of issues in the past?

If the general consensus from the Go community is that these should not be marked as generated and thus should be reviewed, then lets (@pchaigno, @Alhadis or me) go ahead and click the Revert button. If we could get some referenceable guidelines, that would be an added bonus so we can avoid a debate about this in future.

@mvdan
Copy link

mvdan commented Nov 20, 2018

You could have a look at https://github.com/golang/go/wiki/Modules#gomod or https://github.com/golang/go/wiki/Modules#faqs--gomod-and-gosum.

There's no specific entry in the FAQ about whether these files should be hidden during code reviews. But no part of the document says that they should be ignored or treated like generated files.

@pchaigno
Copy link
Contributor

@lildude I'm afraid I don't have the revert button.

@myitcv
Copy link

myitcv commented Nov 20, 2018

@lildude

If we could get some referenceable guidelines, that would be an added bonus so we can avoid a debate about this in future.

Just to add to @mvdan's comments, I would also suggest that a question to https://groups.google.com/forum/#!forum/golang-nuts would also be an excellent way of getting an "official" answer.

@myitcv
Copy link

myitcv commented Dec 1, 2018

@lildude - please can we get an update on this?

@lildude
Copy link
Member

lildude commented Dec 1, 2018

@myitcv sorry, I'm not had a chance to do anything remotely Linguist-based this week and not sure I'll have the time next week. I'd really appreciate it if you could pose this question to the golang-nuts forum to get an idea of which way peeps prefer things - keep as generated or show in diff, both of which can easily be overridden within .gitattributes.

@myitcv
Copy link

myitcv commented Dec 2, 2018

@lildude - there is already a convention for indicating Go-related files are generated:

https://golang.org/s/generatedcode

Add that to the comments above and the wiki link, I don't think this is case of what default people prefer. By default, go.{mod,sum} files should not be marked as generated.

As you say, if people prefer something other than the default (which I can't quite comprehend, because that would mean they prefer not to see changes in the (transitive) dependencies of their projects) they can easily do so.

cc @bcmills from the Go team in case there is anything to add/amend to the above.

@lildude
Copy link
Member

lildude commented Dec 3, 2018

Ah, that's interesting and very useful. Thanks @myitcv. I think we can definitely rely on that as an indicator these files shouldn't be marked as generated (yet) as Go isn't adding the standard text to indicate they should be.

That all said, we can't simply revert this PR as that will take us back to these files not being associated with Go at all leading the behaviour this PR originally attempted to address.

Update: ignore that.

Named file entries would need to added too. I've got a few free mins now so will do it now.

@lildude
Copy link
Member

lildude commented Dec 3, 2018

Booo!!!

screenshot 2018-12-03 at 14 13 42

New PR it is then.

lildude added a commit that referenced this pull request Dec 3, 2018
lildude added a commit that referenced this pull request Jan 16, 2019
* Revert "Treat go.mod and go.sum as generated files. (#4306)"

This reverts commit ba0c5e9.

* Add go.mod and go.sum to Text

* Add test files to fixtures

Files taken from https://github.com/golang/oauth2/ licensed under BSD 3-clause license

* Add test to prevent addition of samples
@github-linguist github-linguist locked as resolved and limited conversation to collaborators Jun 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants