You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Imports returned by `language.Resolvers().ResolveImports()` are represented as [ImportNode](/core/ast/import.go) in a language agnostic manner. It has following fields -
4
+
5
+
-`moduleNameNode` exposed by `ModuleName`
6
+
7
+
The sitter node referring to the imported package or module. It contains entire module name, a non-empty string which can be resolved to the target package or source file on the disk.
8
+
9
+
eg. In python, ModuleName `x.y.z` is resolved for imports - `from x.y.z import p` is `x.y.z`, `import x.y.z` or `import x.y.z as xz`
10
+
11
+
eg. In javascript, ModuleName can be `../relative/import`, `@gilbarbara/eslint-config`, `express`
12
+
13
+
-`moduleItemNode` exposed by `ModuleItem`
14
+
15
+
The sitter node referring to the specific item (function, class, variable, etc) imported from the `ModuleName` mentioned above. It is an empty string if the entire module is imported.
16
+
17
+
eg. For python import `from sklearn import dastasets as ds` is resolved to ModuleItem - `datasets`
18
+
19
+
eg. For javascript import `import { hex } from 'chalk/ansi-styles'`, ModuleItem is `hex`
20
+
21
+
-`moduleAliasNode` exposed by `ModuleAlias`
22
+
23
+
The sitter node referring to alias of the import in the current scope. It is mapped as equivalent to the `ModuleItem` (if it is empty, then `ModuleName`). If no alias is specified in code, then it contains the node for actual Moduleltem or ModuleName.
24
+
25
+
eg. For python import `from sklearn import datasets as ds`, alias is `ds` referring to ModuleItem - `datasets`
26
+
However, for `import pandas as pd`, alias `pd` refers to ModuleName - `pandas` since ModuleItem is empty.
27
+
28
+
-`isWildcardImport` exposed by `IsWildcardImport`
29
+
30
+
Boolean flag Indicating whether the import is a wildcard import
31
+
32
+
eg. In python - `from seaborn import *`
33
+
34
+
eg. In java - `import java.util.*`
35
+
36
+
37
+
## Note
38
+
For composite imports, multiple `ImportNode`s are generated.
39
+
For example, `import ReactDOM, { render, flushSync as flushIt } from 'react-dom'` is resolved to three import nodes -
`UsageEvidence` represents the evidence of usage of a module item in a file. Fields -
4
+
5
+
- PackageHint - string
6
+
7
+
Imported modules aren't exactly same as packages they refer to. It can be a submodule with separators or the top-level module may not match exact package name. As a usage evidence, PackageHint reports the hint of actual dependency being used.
8
+
9
+
For example, the `PyYAML` package is imported as `yaml` or `yaml.composer` where the imported top level module `yaml` isn't equal to the package name.
10
+
11
+
PackageHint is resolved from the `ModuleName` provided by [ImportNode](/core/ast/import.go) by resolving the base module and searching it in the top-level module to dependency mapping [Read more](https://github.com/safedep/code/issues/6).
12
+
13
+
14
+
Moreover, this may not be the final truth, since different languages & package managers may have some package aliasing eg. Shadow JAR in java. Hence, it is just a "hint".
15
+
This can be verified or enriched accurately by the consumer of this API using the required package manifest information which isn't in scope of code analysis framework.
16
+
17
+
- Identifier - string
18
+
19
+
The identifier that was mentioned in the code leading to this Usage evidence. It can be an imported function, class or variable.
20
+
21
+
eg.
22
+
```python
23
+
import ujson
24
+
ujson.decode('{"a": 1, "b": 2}')
25
+
```
26
+
27
+
Here, the identifier `ujson` was used, leading to this UsageEvidence
28
+
29
+
- FilePath - string
30
+
31
+
File path where the dependency was used
32
+
33
+
- Line - uint
34
+
35
+
Line number where the usage was found
36
+
37
+
Note - Line number of usage is reported, not the import
38
+
39
+
Fields taken directly from ImportNode. [Read more](imports.md)
0 commit comments