Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Add exceptions support for comment-format rule (fixes #562) #1757

Merged
merged 4 commits into from
Jan 8, 2017

Conversation

IllusionMH
Copy link
Contributor

@IllusionMH IllusionMH commented Nov 20, 2016

PR checklist

What changes did you make?

This PR adds support for exceptions list to comment-format rule.
Implementation uses array of exceptions as last argument.

Is there anything you'd like reviewers to focus on?

1. Is there a need to escape special characters in exception list to avoid broken RegEx'es?
2. Does exceptions array in last position good choice until #1738 implemented?

P.S. Is it possible to set tests timeout for executable to 3000ms? This will help me a lot, since some tests take ~2500ms under when I run tests in Docker container.

@nchen63
Copy link
Contributor

nchen63 commented Nov 21, 2016

@IllusionMH I extended timeout for executable to 4s in #1766

type: "string",
enum: ["check-space", "check-lowercase", "check-uppercase"],
}, {
type: "array",
Copy link
Contributor

Choose a reason for hiding this comment

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

would it be better to just make this a single regex string since the code makes it into a reg expression anyways? Also, people might see weird behavior if they don't know it's a regex.

Copy link
Contributor

Choose a reason for hiding this comment

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

on second thought, it's probably better the way it is...

Copy link
Contributor Author

@IllusionMH IllusionMH Nov 21, 2016

Choose a reason for hiding this comment

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

I've checked list of ESLint rules and they use RE to provide patterns, however they use object with "ignorePattern" key to provide it.

As alternative approach I can implement exception argument as object with two possible keys ignoreWords - array of strings to ignore and ignorePattern - string with RE to ignore, instead of array of words. Users can select either of two, which suit best for their needs.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, would suggest an object with key for future extensibility

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I'll rework this PR to use object instead of array.
And one more question: Is current state of options in rule metadata correct for case with array?

I not sure if I correctly get this format especially when there should be 2 types of items in array - strings and array (unfortunately I can't find docs with description or sources that process it)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not that familiar with JSON schema, but don't you want anyOf instead of oneOf?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the tip, I'll check Schema docs then. (haven't used JSON Schema before and didn't realize that TSLint uses it)

@IllusionMH
Copy link
Contributor Author

@IllusionMH I extended timeout for executable to 4s in #1766

@nchen63 thank you!

I've noticed that I forgot to update  optionsDescription, and I will submit fix later this week (and address any other requests).

@adidahiya
Copy link
Contributor

@IllusionMH could you please enable Circle CI on your fork?

@IllusionMH
Copy link
Contributor Author

@adidahiya added. But for some reason it doesn't run build on all 3 Node.js versions.
Also I haven't synced this branch with master.

@adidahiya
Copy link
Contributor

Your CI build looks fine, it is running different node versions in 3 containers (maybe you went and enabled multiple containers in the hour since you posted your last comment :))

@IllusionMH
Copy link
Contributor Author

IllusionMH commented Dec 12, 2016

@adidahiya yes, now it runs in 3 containers, however failed/stopped few times when I tried to setup them.

Moreover build on master runs fine in my fork (both have same last commit d053355 ) 😃

Do I need to do any other actions with CI?

@adidahiya adidahiya assigned adidahiya and unassigned adidahiya Dec 13, 2016
@IllusionMH IllusionMH force-pushed the comment-format-exceptions branch from aba85ee to 6fe20ce Compare January 7, 2017 00:14
@IllusionMH
Copy link
Contributor Author

I've rebased this branch and resolved conflicts.

@nchen63, @adidahiya is there anything that should be addressed in this PR?

Copy link
Contributor

@nchen63 nchen63 left a comment

Choose a reason for hiding this comment

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

Sorry the review took so long

type: "style",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */

public static LOWERCASE_FAILURE = "comment must start with lowercase letter";
public static UPPERCASE_FAILURE = "comment must start with uppercase letter";
public static LOWERCASE_FAILURE = "comment must start with lowercase letter, word from exceptions list or exceptions pattern";
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you print the list of exceptions or regex exception in the error? I think most people wouldn't know what an "exceptions list" is when seeing this error.

Copy link
Contributor Author

@IllusionMH IllusionMH Jan 7, 2017

Choose a reason for hiding this comment

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

Thanks! Good point.
Is it ok if there will be 3 different messages instead of one generic?
comment must start with lowercase letter
comment must start with lowercase letter or word from exceptions list: TODO, HACK
comment must start with lowercase letter or match exceptions pattern: STD(IN|OUT|ERR)\b

And same for uppercase option.

Copy link
Contributor

@nchen63 nchen63 Jan 7, 2017

Choose a reason for hiding this comment

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

3 different messages are ok.

I'd avoid using the word "exceptions" since it could confuse people with the kind of exception you throw. Something like Comment must start with a lowercase letter, or the words "TODO", or "HACK" and Comment must start with a lowercase letter or match the regex pattern "STD(IN|OUT|ERR)\b

@IllusionMH
Copy link
Contributor Author

@nchen63 I've updated messages.
Message for ignore words was simplified to avoid differences for cases where single or several words are specified.
Message for ignore pattern was extended to specify that start of the comment will be matched against regexp and not a whole comment.

@nchen63 nchen63 merged commit 11d1281 into palantir:master Jan 8, 2017
@nchen63
Copy link
Contributor

nchen63 commented Jan 8, 2017

@IllusionMH thanks!

@IllusionMH IllusionMH deleted the comment-format-exceptions branch January 8, 2017 12:23
@nchen63
Copy link
Contributor

nchen63 commented Jan 23, 2017

I realized as I was compiling the release notes that the option ignoreWords should probably be ignore-words

@nchen63 nchen63 mentioned this pull request Jan 23, 2017
3 tasks
@IllusionMH
Copy link
Contributor Author

@nchen63 you are right. typedef-whitespace has config object with hyphens in keys.
I have stupid question: when rule docs should be updated? In every pull request or they are generated right before release?
Docs don't describe requirement here and I remember cases when docs weren't required between 3.15 and 4.0 releases.

@nchen63
Copy link
Contributor

nchen63 commented Jan 23, 2017

Docs are generated and published with the release. I've recently added the generated docs to .gitignore, so it's not possible to update in any case.

@IllusionMH
Copy link
Contributor Author

@nchen63 thanks, PR is on the way

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants