-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
New Rule: keys-patterns #55
Comments
Thanks for the suggestion. I understand what you're trying to do, but I'm not sure it's universal enough to include in this plugin. (Keep in mind, you can always just write the rule yourself -- it doesn't need to be in this plugin for it to exist.) {
"keys-patterns": [
"error",
{
"/(^[a-zA-Z]+_i18n$)/": ["./src/i18n/en.json", "./src/i18n/it.json"],
"/(^[a-zA-Z]$)/": ["./src/some.json"],
}
]
} I'm not sure what this is supposed to do. If you want different settings for different files, the canonical ESLint way of doing it would be: export default [
{
files: ["./src/i18n/en.json", "./src/i18n/it.json"],
rules: {
"keys-patterns": [ "error", "/(^[a-zA-Z]+_i18n$)/"]
}
},
{
files: ["./src/some.json"],
rules: {
"keys-patterns": [ "error", "/(^[a-zA-Z]$)/"],
}
},
]; @eslint/eslint-team thoughts? |
As with #54, agreed that this seems specific to one library's use cases. -1 from me on the specific rule. On the other hand, I think there could be utility in adding an equivalent to
|
I agree this doesn't seem universal to include in this plugin.
Yes, the core This config should work for the example from the original post: import json from "@eslint/json";
export default [
{
files: ["**/*.json"],
plugins: {
json
},
language: "json/json"
},
{
files: ["src/i18n/en.json", "src/i18n/it.json"],
rules: {
"no-restricted-syntax": [
"error",
{
selector: "Member > String[value!=/^[a-zA-Z]+_i18n$/].name",
message: "Object keys should match /^[a-zA-Z]+_i18n$/"
}
]
}
},
{
files: ["src/some.json"],
rules: {
"no-restricted-syntax": [
"error",
{
selector: "Member > String[value!=/^[a-zA-Z]$/].name",
message: "Object keys should match /^[a-zA-Z]$/"
}
]
}
}
]; |
Thanks, I'll try to use the |
Yes, we can do that. At some point, we probably want to split it out of the core into its own plugin, though, to avoid this ambiguity. |
Rule details
Allows to set a keys patters to specific JSON files
What type of rule is this?
Suggests an alternate way of doing something
Example code
Real life example:
I have a JSON files for application localization
I want to prohibit adding keys to it that do not match a certain pattern (for this example /(^[a-zA-Z]+_i18n$)/)
I propose to add rule which add an ability to set patters to specific JSON files
Rule example:
Different patterns can be assigned to different files. If you do not specify anything for file, there will be no pattern
Participation
Additional comments
In my example, there is a JSON file without nesting. If we have nesting maybe this rule will not be necessary, a schema is already needed there, but we can discuss it here
The text was updated successfully, but these errors were encountered: