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

NEW: Add support for parsers and the first parser. #720

Closed
wants to merge 10 commits into from
Closed

Conversation

sarvaje
Copy link
Contributor

@sarvaje sarvaje commented Dec 15, 2017

Pull request checklist

Make sure you:

For non-trivial changes, please make sure you also:

  • Added/Updated related documentation.
  • Added/Updated related tests.

Short description of the change(s)

}

private parseJavascript(fetchEnd: IFetchEnd) {
if (fetchEnd.response.mediaType !== 'text/javascript') {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about application/javascript? I know a few issues were opened in sonarwhal discussing which media type is right, but here maybe both should be considered?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The response.mediaType is calculated in sonar, and in case of a javascript, it will be always text/javascript

if you can understand it. A good approach would be:

1. check first the `mediaType` of the response (`fetchEndEvent#response#mediaType#`)
2. use a schema to validate if `json` or `xml` or something similar
Copy link
Contributor

Choose a reason for hiding this comment

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

json, xml, or something similar

event is emitted for all downloaded resources, you need to check first
if you can understand it. A good approach would be:

1. check first the `mediaType` of the response (`fetchEndEvent#response#mediaType#`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be: fetchEndEvent.response.mediaType?

@sarvaje
Copy link
Contributor Author

sarvaje commented Dec 15, 2017

@alrra done!


The built-in `parser`s are:

* `javascript`: A `JavaScript` parser built on top of `ESLint` so rules for
Copy link
Member

Choose a reason for hiding this comment

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

We need to add more information on how a rule can subscribe to this events and create rules based on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have some rule in mind? Can it be addressed in another PR?

Copy link
Member

Choose a reason for hiding this comment

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

Documentation on what's exposed via the parser and how to use it should be in this PR IMO.

Copy link
Contributor Author

@sarvaje sarvaje Dec 18, 2017

Choose a reason for hiding this comment

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

@molant I have added something else to the documentation.


const scriptContentRegex: RegExp = /^<script[^>]*>([\s\S]*)<\/script>$/;
const defaultParserOptions = {
comment: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add a comment why we are using these options by default, and maybe a link?

}


private isJavascript(element: IAsyncHTMLElement) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you rename this to something such as: isJavaScriptType.

this.emitScript(code, resource);
}

private isSrcPresent(element: IAsyncHTMLElement) {
Copy link
Contributor

@alrra alrra Dec 18, 2017

Choose a reason for hiding this comment

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

Can you rename this to: hasSrcAttribute?

@sarvaje
Copy link
Contributor Author

sarvaje commented Dec 18, 2017

@alrra done!

@sarvaje
Copy link
Contributor Author

sarvaje commented Dec 22, 2017

I have added the wizard to create new core/external parsers.

@molant
Copy link
Member

molant commented Jan 3, 2018

@sarvaje there are conflicts here. Can you fix them? Also there seems to be errors with AppVeyor?

@sarvaje
Copy link
Contributor Author

sarvaje commented Jan 3, 2018

@molant I think the error with appVeyor is not related with this PR :s

@sarvaje
Copy link
Contributor Author

sarvaje commented Jan 3, 2018

@molant conflics solved

@alrra alrra closed this in 511bba9 Jan 4, 2018
@alrra alrra deleted the parsers branch January 4, 2018 18:08
@molant
Copy link
Member

molant commented Jan 4, 2018

🎉

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

4 participants