Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Detect common mistakes in snippets.(c|j)son files #13

Open
1 task done
savetheclocktower opened this issue Feb 27, 2023 · 0 comments
Open
1 task done

Detect common mistakes in snippets.(c|j)son files #13

savetheclocktower opened this issue Feb 27, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@savetheclocktower
Copy link

savetheclocktower commented Feb 27, 2023

Have you checked for existing feature requests?

  • Completed

Summary

There are a couple of mistakes that I think are easy to make in user snippet files. Both could be detected somewhat easily.

Scopes missing initial .

Atom chose early on to treat scope names like CSS class names in many contexts, but it’s not always clear exactly what the expectation is for a specific usage. You can run Editor: Log Cursor Scope and see a list of scopes without initial .s, much like TextMate — e.g., source.js. But any context that uses ScopedPropertyStore under the hood will need the initial dot — e.g., .source.js.

This would be very easy to catch when consuming a user’s snippets file — both on window initialization and after the user makes a change and saves it. If any top-level key does not start with a dot, that’s 100% a mistake. We could also check for missing dots after commas. I don’t think we’d be able to know the exact fix 100% of the time, but just mentioning the problem to the user would be a major improvement over the status quo.

Duplicate keys in snippets.json files

It’s really easy to include a duplicate top-level key in your snippets.cson, but if you do it by accident, we point it out immediately. That’s a huge help. It happens because season has an allowDuplicateKeys option that, when set to false, will throw an error upon encountering a duplicate key.

Sadly, we don’t get this behavior for JSON files. Season will parse JSON files without complaints, but only because it delegates to the built-in JSON.parse when it detects them. So allowDuplicateKeys: false has no effect when parsing a JSON file.

This might not be a big deal. I know we allow a snippets.json file if it exists, but I have no idea how many users choose to reject the default snippets.cson and make a new JSON file. Probably not that many.

What benefits does this feature provide?

More user-friendly, especially to new users. Catches a common mistake before people feel the need to ask for help on GitHub or Discord.

Any alternatives?

One alternative would be to abstract away the difference between (e.g.) source.js and .source.js in all contexts. That would be quite an undertaking, but arguably worth doing. That's a can of worms I won't open right now.

@savetheclocktower savetheclocktower added the enhancement New feature or request label Feb 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant