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

Enhance TokenStore methods with includeComments option #8068

Closed
kaicataldo opened this issue Feb 12, 2017 · 2 comments · Fixed by renovatebot/renovate#111 · May be fixed by iamhunter/teammates#4
Closed

Enhance TokenStore methods with includeComments option #8068

kaicataldo opened this issue Feb 12, 2017 · 2 comments · Fixed by renovatebot/renovate#111 · May be fixed by iamhunter/teammates#4
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion

Comments

@kaicataldo
Copy link
Member

kaicataldo commented Feb 12, 2017

Having used the new TokenStore token traversal methods this week (while working on this PR), I think we should add an includeComments option to the following: getTokenByRangeStart(), getTokens(), and getTokensBetween().

The API I'm envisioning is:

getTokenByRangeStart(index, {
    includeComments: true
});

getTokens(node, {
    beforeCount: 0,
    afterCount: 0,
    includeComments: true,
    filter: filterFn
});

getTokensBetween(leftToken, rightToken, {
    padding: 0,
    includeComments: true,
    filter: filterFn
});

The proposed change to getTokenByRangeStart() is not a breaking change, but the other two are (though I suppose we could do this in a backwards compatible manner still). I'd ideally like to use getTokens in the aforementioned PR here.

Also wanted to note that the beforeCount, afterCount, and padding options are all undocumented and look like they were included to avoid a breaking change.

cc @mysticatea

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Feb 12, 2017
@kaicataldo kaicataldo added breaking This change is backwards-incompatible core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion tsc agenda This issue will be discussed by ESLint's TSC at the next meeting and removed triage An ESLint team member will look at this issue soon labels Feb 12, 2017
@mysticatea
Copy link
Member

Actually, getTokens and getTokensBetween are supporting includeComments and filter options. Though those object-style options are not supporting padding option.

interface CountOptions {
    includeComments?: boolean
    filter?: (token: Token|Comment) => boolean
    count?: number
}

interface TokenStore {
    //...

    getTokens(node: Node): Token[]
    getTokens(node: Node, beforeCount: number, afterCount: number): Token[]
    getTokens(node: Node, filter: (token: Token) => boolean): Token[]
    getTokens(node: Node, options: CountOptions): (Token|Comment)[]
    
    getTokensBetween(left: Node|Token|Comment, right: Node|Token|Comment): Token[]
    getTokensBetween(left: Node|Token|Comment, right: Node|Token|Comment, padding: number): Token[]
    getTokensBetween(left: Node|Token|Comment, right: Node|Token|Comment, filter: (token: Token) => boolean): Token[]
    getTokensBetween(left: Node|Token|Comment, right: Node|Token|Comment, options: CountOptions): (Token|Comment)[]
}

@kaicataldo kaicataldo removed breaking This change is backwards-incompatible tsc agenda This issue will be discussed by ESLint's TSC at the next meeting labels Feb 12, 2017
@kaicataldo
Copy link
Member Author

@mysticatea Ah, sorry then - thanks for the explanation. I'd still like to propose the change to getTokenByRangeStart(), but since that's no longer a breaking change, I'll just open a PR (have one ready based on our last discussion @mysticatea).

pantosha pushed a commit to pantosha/eslint that referenced this issue Feb 21, 2017
… (eslint#8069)

* Update: Add includeComments to getTokenByRangeStart (fixes eslint#8068)

* Remove @Private from public methods
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion
Projects
None yet
3 participants