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

[baseline output] Add sort_keys=True to json.dumps #25

Merged
merged 2 commits into from
Jun 14, 2018

Conversation

KevinHock
Copy link
Collaborator

@KevinHock KevinHock commented Jun 14, 2018

This prevents unnecessary baseline modifications where the pre-commit hook can change the baseline only to re-order keys around (on certain python versions.)

Note that this will make it read differently then before, but in my opinion it's even more readable as the exclude_regex is no longer at the bottom after the results.

With sort_keys it is e.g.

{
  "exclude_regex": null,
  "generated_at": "2018-06-14T20:55:58Z",
  "plugins_used": [
    {
      "limit": 4.5,
      "name": "Base64HighEntropyString"
    },
    {
      "limit": 3,
      "name": "HexHighEntropyString"
    },
    {
      "name": "PrivateKeyDetector"
    }
  ],
  "results": {
    "test_data/baseline.file": [
      {
        "hashed_secret": "fdd121830f7c0a035298a08a79c7a34835184b8a",
        "line_number": 9,
        "type": "High Entropy String"
      },
      {
....
  },
  "exclude_regex": null
}

Whereas without sort_keys it is e.g.

  "plugins_used": [
    {
      "limit": 4.5,
      "name": "Base64HighEntropyString"
    },
    {
      "limit": 3,
      "name": "HexHighEntropyString"
    },
    {
      "name": "PrivateKeyDetector"
    }
  ],
  "generated_at": "2018-06-14T20:55:23Z",
  "results": {
    "tests/pre_commit_hook_test.py": [
      {
        "line_number": 154,
....
  },
  "exclude_regex": null
}

@KevinHock KevinHock requested a review from domanchi June 14, 2018 21:08
@domanchi
Copy link
Contributor

You probably want to do it in other places too.

E.g. https://github.com/Yelp/detect-secrets/blob/master/detect_secrets/pre_commit_hook.py#L57

@KevinHock
Copy link
Collaborator Author

Great catch!

@KevinHock KevinHock changed the title [baseline output] Add sorted_keys=True to json.dumps [baseline output] Add sort_keys=True to json.dumps Jun 14, 2018
@KevinHock KevinHock merged commit 567a981 into master Jun 14, 2018
@KevinHock KevinHock deleted the 24_fix_baseline_order branch June 15, 2018 21:31
gpflaum pushed a commit to gpflaum/detect-secrets that referenced this pull request Aug 30, 2021
porting azure storage key from upstream yelp
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.

None yet

2 participants