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

Exclude JSON identifiers from parsing #18

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ module.exports = {
checkString(value, node);
},
JSONLiteral(node){
const { value } = node;
const { value, parent } = node;
const nodeIsIdentifier = parent.type === 'JSONProperty' && parent.key === node
if (nodeIsIdentifier) return;

Choose a reason for hiding this comment

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

If you want to exclude the JavaScript property name from the check as well, you'll need to make the same changes to the JavaScript check method.

Copy link
Owner

Choose a reason for hiding this comment

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

Thank you for the help @ota-meshi! @constgen if you'd like to include that check in the PR, let me know.

Copy link
Author

Choose a reason for hiding this comment

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

Now I realized. These two JS expressions produce different AST nodes:

  1. { name: 'value' } - name is Identifier type
  2. { 'name': 'value' } - 'name' is Literal type

So I am going to add additional checks for JS too

Copy link
Author

Choose a reason for hiding this comment

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

Excluded property names from parsing and added a test for this. But tests are not run automatically on any CI/CD

checkString(value, node);
}
};
Expand Down