Skip to content

Conversation

@DecimalTurn
Copy link
Contributor

@DecimalTurn DecimalTurn commented Sep 23, 2025

This pull request introduces a note mentioning .gitattributes overrides when using the --strategies option. It also adds small integration tests to verify that CLI behavior reflects these changes while preserving the normal behavior when --strategies is not specified.

Language detection improvements:

  • When a linguist-language attribute is present in the .gitattributes file for the analyzed file, a note is added to mention the override.

Testing and instrumentation enhancements:

  • Added tests to test_basic_instrumenter.rb to verify that the detection strategy and language are correctly tracked when .gitattributes overrides are present and the strategy information is displayed correctly.

CLI integration and coverage:

  • Added a new test_cli_integration.rb suite with tests for CLI flags (--strategies, --breakdown, --json) to ensure that .gitattributes overrides are detected, the correct strategy info is reported, and JSON output remains accurate.

@DecimalTurn DecimalTurn requested a review from a team as a code owner September 23, 2025 05:04
@Alhadis
Copy link
Collaborator

Alhadis commented Sep 23, 2025

I think it would be clearer to users if we reported "(overridden by [path/to/.gitattributes])" instead of merely "GitAttributes" (as there's really only one that affects Linguist's classification).

So instead of treating linguist-language overrides as a faux-strategy, perhaps tailor the output to include an [overridden] flag, possibly prepended to the strategy that would otherwise have matched in the absence of the override.

@DecimalTurn
Copy link
Contributor Author

DecimalTurn commented Sep 23, 2025

Sounds good, I've made the change to display the information like so:

<FilePath> [<StrategyName> (overridden by .gitattributes)]

This change means that detection has to take place even when there is an override in order to determine what strategy would be used. However, the changes in e879628 also introduce a check on Linguist.instrumenter to see if its defined before running the full detection (this is equivalent to check if --strategies was specified). This way, we keep the lazy approach if the strategy isn't needed.

Adding the .gitattributes path seems to be too complicated to implement for what it adds, but I'm not against the idea in principle.

@DecimalTurn DecimalTurn changed the title Add .gitattributes override as a strategy Add .gitattributes override mention when returning the strategy Sep 23, 2025
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.

Seems like a good idea to me. Can you please also update the README.md to document and show the output this change introduces.

@DecimalTurn
Copy link
Contributor Author

DecimalTurn commented Oct 9, 2025

Seems like a good idea to me. Can you please also update the README.md to document and show the output this change introduces.

In the latest commits, I've added:

  • An intro section about the different modes (Git Repository vs Single file)
  • Documentation about --strategies in Git Repository mode
  • Documentation about all relevant flags in Single file mode

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.

4 participants