-
Notifications
You must be signed in to change notification settings - Fork 14
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
report line numbers in custom lints rules #791
Comments
@jessegreenberg is going to take a look at this as part of #732. |
This is an issue for rules that search for issues through the whole text the context One way to fix this is to check for bad text on all Ill go with |
If performance is a concern, we could do the same checking as we do now to find a problem, and then dive in only in bad files to determine the right LOC. |
I ran On my machine the test took 1 minute 11 seconds with token method and 1 minute with the source code search method. 10 seconds is not a problem for me, though others may disagree. It probably won't be noticeable when running I also noticed that after ff56fb0 it is catching a few more usages of |
I addressed the issues with Math.round in the preceding commit. |
@jessegreenberg I think it is important for this issue to also delete all the places on the top of the file where |
I think that after ff56fb0, can only support word characters. I'm not totally sure, but adding I came to this issue while working on phetsims/phet-core#71 |
I'm working on a potential solution. will comment shortly |
Over in 1fcccd2, I created a new lint rule, which is largely experimental, called @jessegreenberg I really appreciate the work you put into this type to convert it to using tokens. It was really helpful as a jumping off point for |
In the above commits I added a bit more support for bad text that spreads across multiple tokens. I did this by formalizing a schema that takes a string as well as a tokenized list of code parts that can be used while iterating through all the code tokens in a file. I also improved performance by testing to see if the source-code text included the string version of the bad-text before diving into iterating through tokens. This exposed 3 lint errors that crept in in the last few weeks. I added workarounds to them all, but think that phetsims/number-line-integers#37 will likely need to be fixed instead of ignored. @jessegreenberg would you please review my commits, especially for documentation and general understanding. I want it to both be powerful as well as easy to understand, and I don't yet know where the code fits on that scale just yet. My next steps for lint rules will be
|
|
OK cool, very good! I don't think I understand how the updated I think that the direction listed #791 (comment) and in #808 is correct. |
It doesn't look like this is working quite yet. In phetsims/energy-skate-park#140 (comment) a few cases of |
Yes that rule is currently not supported with line numbers. I think we will need to create a custom lint rule just for it in order to get it right. The reason is that
and I added a "workaround" just for that rule, in which is will still error out globally, with a bad line number. That felt better than nothing. |
For the workaround cases, would it be better to just text search the file line by line (ignoring the parsed esprima node structure)? |
I tried this in // If marked as global, then report the global failure based on the source code indexOf check
if ( forbiddenText.global ) {
for ( let i = 0; i < codeLines.length; i++ ) {
const columnIndex = codeLines[ i ].indexOf( forbiddenText.id );
if ( columnIndex >= 0 ) {
// lines are 1 based, codeLines array is 0 based
const badLine = i + 1;
// esprima Token loc object, see https://esprima.readthedocs.io/en/latest/lexical-analysis.html
const loc = {
start: { line: badLine, column: columnIndex },
end: { line: badLine, column: columnIndex + forbiddenText.id.length }
};
context.report( {
node: node,
loc: loc,
message: 'File contains bad text: \'' + forbiddenText.id + '\''
} );
break;
}
}
} Where codeLines is @zepumph do you think that this could be used for all bad text and replace the method of looking through tokens? |
That looks promising. I'll try to take a look this Thursday at it. |
@jessegreenberg your code snippet in #791 (comment) was very helpful, and it simplified a bunch of code. Here is now the basic alrgorithm:
Because of your code snippet, much of the api around I still have one lint rule commented out until phetsims/energy-skate-park#140 is fixed. Please review. Anything else here? |
I hadn't thought of that and I agree, good idea, thanks. This looks nice and it is highlighting the location of all bad text in my editor and in the console. I can quickly address phetsims/energy-skate-park#140 now. |
@zepumph said in #732 (comment):
First step is probably to make a list of which lint rules have this problem.
The text was updated successfully, but these errors were encountered: