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

add dict-string-keys rule #10107

Merged
merged 2 commits into from Jun 26, 2017
Merged

Conversation

erwinmombay
Copy link
Member

enforces that the keys of the object passed into dict has to be
strings and should be quoted.

Fixes #10094

return;
}

arg1.properties.forEach(function(prop) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you make this recurse if the value is also an object literal?

Basically:

If value is object literal, also check that all its keys are literals.

Copy link
Member Author

Choose a reason for hiding this comment

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

doh, yeah forgot about that

Copy link
Member Author

Choose a reason for hiding this comment

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

@cramforce done. unfortunately if the the value is a reference (Identifier node) i can't really look it up and recursively check the reference (if its an array or object and its values/keys)

Copy link
Member

Choose a reason for hiding this comment

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

That is fine.

}

arg1.properties.forEach(function(prop) {
if (!prop.key.raw) {
Copy link
Member

Choose a reason for hiding this comment

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

Raw stands for literal?

Copy link
Member Author

Choose a reason for hiding this comment

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

if the Key Node has a "raw" property then it is a string literal (value will be the quoted string), else it will have a name property

enforces that the keys of the object passed into `dict` has to be
strings and should be quoted.
@erwinmombay erwinmombay merged commit 0122f30 into ampproject:master Jun 26, 2017
cramforce added a commit to cramforce/amphtml that referenced this pull request Jul 2, 2017
We enforce via the linter (ampproject#10107) that arguments to `dict` are object literals. So, there is no need to copy.

Part of  ampproject#9876
cramforce added a commit that referenced this pull request Jul 2, 2017
We enforce via the linter (#10107) that arguments to `dict` are object literals. So, there is no need to copy.

Part of  #9876
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants