-
Notifications
You must be signed in to change notification settings - Fork 13
[Linter]: Support for deprecated arguments #2630
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
Open
gigalasr
wants to merge
22
commits into
main
Choose a base branch
from
1870-deprecated-args-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c097974
feat(lint): add structure for deprectaed args - #1870
gigalasr 9116b6e
feat(lint): only detect when deprectaed arg is present - #1870
gigalasr 05e92b8
feat(lint): allow new metadata in functions as well - #1870
gigalasr a43d0bc
feat(lint): pretty print new deprecation info - #1870
gigalasr 493606b
feat(lint): use source location of arg - #1870
gigalasr 5efa7cc
Merge remote-tracking branch 'origin/main' into 1870-deprecated-args-…
gigalasr e59b179
Merge remote-tracking branch 'origin/main' into 1870-deprecated-args-…
gigalasr b4a79ba
feat-fix(lint): use new RRange util - #1870
gigalasr ae5965b
docs(eval): describe interface and deprecation state - #1870
gigalasr 314adc7
feat(dep): cleaner config - #1870
gigalasr 1172cd3
Merge remote-tracking branch 'origin/main' into 1870-deprecated-args-…
gigalasr 2c89bc7
feat(dep): support for version checking - #1870
gigalasr 118a07d
Merge remote-tracking branch 'origin/main' into 1870-deprecated-args-…
gigalasr 6f0049e
feat(dep): version check for functions #1870
gigalasr e36782b
feat(lint): ifValue support for deprecated args - #1870
gigalasr 7a80a2a
Merge remote-tracking branch 'origin/main' into 1870-deprecated-args-…
gigalasr 6bb30fc
lint(linter): eslint fixes - #1870
gigalasr fa811e5
feat(lint): use identifier - #1870
gigalasr ae6c74f
feat(lint): try to fix derrived range - #1870
gigalasr f69a89b
Merge remote-tracking branch 'origin/main' into 1870-deprecated-args-…
gigalasr 8d9cbfd
feat(depr): use guess-dep querry - #1870
gigalasr f05e5e0
Merge remote-tracking branch 'origin/main' into 1870-deprecated-args-…
gigalasr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,135 @@ | ||
| import { LintingRuleCertainty, type LintingRule } from '../linter-format'; | ||
| import type { BrandedIdentifier } from '../../dataflow/environments/identifier'; | ||
| import { FunctionArgument } from '../../dataflow/graph/graph'; | ||
| import { isFunctionCallVertex } from '../../dataflow/graph/vertex'; | ||
| import { Enrichment, enrichmentContent } from '../../search/search-executor/search-enrichers'; | ||
| import { isNotUndefined } from '../../util/assert'; | ||
| import { SourceLocation } from '../../util/range'; | ||
| import { LintingResultCertainty, LintingRuleCertainty, type LintingRule } from '../linter-format'; | ||
| import { LintingRuleTag } from '../linter-tags'; | ||
| import { type FunctionsMetadata, type FunctionsResult, type FunctionsToDetectConfig, functionFinderUtil } from './function-finder-util'; | ||
|
|
||
| /** | ||
| * Information about an argument of a function that should be flagged as deprected if it is called with this argument | ||
| */ | ||
| export interface DeprecatedArgumentInformation { | ||
| argIdx?: number, | ||
| argName?: string | ||
| ifValue?: RegExp | string | ||
| replacedBy?: string | ||
| version?: string | ||
| state: DeprecationState | ||
| } | ||
|
|
||
| export const enum DeprecationState { | ||
| /** | ||
| * Still works, but marked for removal | ||
| */ | ||
| Deprecated, | ||
| /** | ||
| * No longer works, and marked for removal | ||
| */ | ||
| Defunct, | ||
| /** | ||
| * Replaced by another function but kept for compatibility | ||
| */ | ||
| Superseeded | ||
| } | ||
|
|
||
| export interface DeprecatedFunctionsConfig<Fns extends readonly string[] = readonly string[]> extends FunctionsToDetectConfig { | ||
| /** | ||
| * Functions to mark as deprecated | ||
| */ | ||
| fns: Fns | ||
| /** | ||
| * Additionally, constraint the detection of an fn in {@link DeprecatedFunctionsConfig.fns} if it is called with an Argument | ||
| * defined by {@link DeprecatedFunctionsConfig.whenArgs} | ||
| */ | ||
| whenArgs: Partial<Record<Fns[number], DeprecatedArgumentInformation[]>> | ||
| } | ||
| // Little helper for constraining whenArgs to fns | ||
| const defineConfig = <const Fns extends readonly string[]>(config: DeprecatedFunctionsConfig<Fns>) => config; | ||
|
|
||
| export const DEPRECATED_FUNCTIONS = { | ||
| createSearch: (config) => functionFinderUtil.createSearch(config.fns), | ||
| processSearchResult: functionFinderUtil.processSearchResult, | ||
| prettyPrint: functionFinderUtil.prettyPrint('deprecated'), | ||
| info: { | ||
| processSearchResult: async(elements, config, data) => { | ||
| const dataflow = (await data.dataflow()).graph; | ||
| const metadata: FunctionsMetadata = { | ||
| totalCalls: 0, | ||
| totalFunctionDefinitions: 0 | ||
| }; | ||
|
|
||
| const results = elements.getElements().flatMap(e => { | ||
| metadata.totalCalls++; | ||
| return enrichmentContent(e, Enrichment.CallTargets).targets.map(target => { | ||
| metadata.totalFunctionDefinitions++; | ||
| return { | ||
| node: e.node, | ||
| loc: SourceLocation.fromNode(e.node), | ||
| target: target as BrandedIdentifier, | ||
| }; | ||
| }); | ||
| }).filter(e => isNotUndefined(e.loc)); | ||
|
|
||
| // Filter out functions that are only deprecated when a certain Argument is present | ||
| const resultsWhenArg = results.flatMap(r => { | ||
| // If not provided in whenArgs, it is always deprecated | ||
| const whenArgs = config.whenArgs[r.target]; | ||
| if(whenArgs === undefined) { | ||
| return r; | ||
| } | ||
|
|
||
| // Check if function has deprecated args | ||
| const deprecatedArgs = whenArgs.map(depricationInfo => { | ||
| const vertex = dataflow.getVertex(r.node.info.id); | ||
| if(vertex === undefined || !isFunctionCallVertex(vertex)) { | ||
| return undefined; | ||
| } | ||
|
|
||
| if(vertex.args.some((arg, idx) => | ||
| FunctionArgument.isNamed(arg) && arg.name === depricationInfo.argName || | ||
| FunctionArgument.isPositional(arg) && idx === depricationInfo.argIdx | ||
| )) { | ||
| return { | ||
| arg: depricationInfo.argName ?? depricationInfo.argIdx, | ||
| state: depricationInfo.state, | ||
| replacedBy: depricationInfo.replacedBy | ||
| }; | ||
| } | ||
| }).filter(p => p !== undefined); | ||
|
|
||
| // Don't mark function as deprecated, if we didn't find any deprecated args | ||
| return deprecatedArgs.length === 0 ? undefined : { | ||
| ...r, | ||
| deprecatedArgs: deprecatedArgs | ||
| }; | ||
| }).filter(p => p !== undefined); | ||
|
|
||
| return { | ||
| results: resultsWhenArg.map(e => ({ | ||
| certainty: LintingResultCertainty.Certain, | ||
| involvedId: e.node.info.id, | ||
| function: e.target, | ||
| loc: e.loc | ||
| })) as FunctionsResult[], | ||
| '.meta': metadata | ||
| }; | ||
| }, | ||
| prettyPrint: functionFinderUtil.prettyPrint('deprecated'), | ||
| info: { | ||
| name: 'Deprecated Functions', | ||
| tags: [LintingRuleTag.Deprecated, LintingRuleTag.Smell, LintingRuleTag.Usability, LintingRuleTag.Reproducibility], | ||
| // ensures all deprecated functions found are actually deprecated through its limited config, but doesn't find all deprecated functions since the config is pre-crawled | ||
| certainty: LintingRuleCertainty.BestEffort, | ||
| description: 'Marks deprecated functions that should not be used anymore.', | ||
| defaultConfig: { | ||
| fns: ['all_equal', 'arrange_all', 'distinct_all', 'filter_all', 'group_by_all', 'summarise_all', 'mutate_all', 'select_all', 'vars', 'all_vars', 'id', 'failwith', 'select_vars', 'rename_vars', 'select_var', 'current_vars', 'bench_tbls', 'compare_tbls', 'compare_tbls2', 'eval_tbls', 'eval_tbls2', 'location', 'changes', 'combine', 'do', 'funs', 'add_count_', 'add_tally_', 'arrange_', 'count_', 'distinct_', 'do_', 'filter_', 'funs_', 'group_by_', 'group_indices_', 'mutate_', 'tally_', 'transmute_', 'rename_', 'rename_vars_', 'select_', 'select_vars_', 'slice_', 'summarise_', 'summarize_', 'summarise_each', 'src_local', 'tbl_df', 'add_rownames', 'group_nest', 'group_split', 'with_groups', 'nest_by', 'progress_estimated', 'recode', 'sample_n', 'top_n', 'transmute', 'fct_explicit_na', 'aes_', 'aes_auto', 'annotation_logticks', 'is.Coord', 'coord_flip', 'coord_map', 'is.facet', 'fortify', 'is.ggproto', 'guide_train', 'is.ggplot', 'qplot', 'is.theme', 'gg_dep', 'liply', 'isplit2', 'list_along', 'cross', 'invoke', 'at_depth', 'prepend', 'rerun', 'splice', '`%@%`', 'rbernoulli', 'rdunif', 'when', 'update_list', 'map_raw', 'accumulate', 'reduce_right', 'flatten', 'map_dfr', 'as_vector', 'transpose', 'melt_delim', 'melt_fwf', 'melt_table', 'read_table2', 'str_interp', 'as_tibble', 'data_frame', 'tibble_', 'data_frame_', 'lst_', 'as_data_frame', 'as.tibble', 'frame_data', 'trunc_mat', 'is.tibble', 'tidy_names', 'set_tidy_names', 'repair_names', 'extract_numeric', 'complete_', 'drop_na_', 'expand_', 'crossing_', 'nesting_', 'extract_', 'fill_', 'gather_', 'nest_', 'separate_rows_', 'separate_', 'spread_', 'unite_', 'unnest_', 'extract', 'gather', 'nest_legacy', 'separate_rows', 'separate', 'spread'] | ||
| } | ||
| defaultConfig: defineConfig({ | ||
| fns: ['geom_violin', 'all_equal', 'arrange_all', 'distinct_all', 'filter_all', 'group_by_all', 'summarise_all', 'mutate_all', 'select_all', 'vars', 'all_vars', 'id', 'failwith', 'select_vars', 'rename_vars', 'select_var', 'current_vars', 'bench_tbls', 'compare_tbls', 'compare_tbls2', 'eval_tbls', 'eval_tbls2', 'location', 'changes', 'combine', 'do', 'funs', 'add_count_', 'add_tally_', 'arrange1_', 'count_', 'distinct_', 'do_', 'filter_', 'funs_', 'group_by_', 'group_indices_', 'mutate_', 'tally_', 'transmute_', 'rename_', 'rename_vars_', 'select_', 'select_vars_', 'slice_', 'summarise_', 'summarize_', 'summarise_each', 'src_local', 'tbl_df', 'add_rownames', 'group_nest', 'group_split', 'with_groups', 'nest_by', 'progress_estimated', 'recode', 'sample_n', 'top_n', 'transmute', 'fct_explicit_na', 'aes_', 'aes_auto', 'annotation_logticks', 'is.Coord', 'coord_flip', 'coord_map', 'is.facet', 'fortify', 'is.ggproto', 'guide_train', 'is.ggplot', 'qplot', 'is.theme', 'gg_dep', 'liply', 'isplit2', 'list_along', 'cross', 'invoke', 'at_depth', 'prepend', 'rerun', 'splice', '`%@%`', 'rbernoulli', 'rdunif', 'when', 'update_list', 'map_raw', 'accumulate', 'reduce_right', 'flatten', 'map_dfr', 'as_vector', 'transpose', 'melt_delim', 'melt_fwf', 'melt_table', 'read_table2', 'str_interp', 'as_tibble', 'data_frame', 'tibble_', 'data_frame_', 'lst_', 'as_data_frame', 'as.tibble', 'frame_data', 'trunc_mat', 'is.tibble', 'tidy_names', 'set_tidy_names', 'repair_names', 'extract_numeric', 'complete_', 'drop_na_', 'expand_', 'crossing_', 'nesting_', 'extract_', 'fill_', 'gather_', 'nest_', 'separate_rows_', 'separate_', 'spread_', 'unite_', 'unnest_', 'extract', 'gather', 'nest_legacy', 'separate_rows', 'separate', 'spread'], | ||
| whenArgs: { | ||
| 'geom_violin': [{ | ||
| argName: 'draw_quantiles', | ||
| state: DeprecationState.Deprecated, | ||
| replacedBy: 'quantile.linetype' | ||
| }] | ||
| } | ||
| }) | ||
| } | ||
| } as const satisfies LintingRule<FunctionsResult, FunctionsMetadata, FunctionsToDetectConfig>; | ||
| } as const satisfies LintingRule<FunctionsResult, FunctionsMetadata, DeprecatedFunctionsConfig>; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.