• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ota-meshi / eslint-plugin-css / 9557703888

18 Jun 2024 01:58AM UTC coverage: 88.309%. Remained the same
9557703888

push

github

web-flow
fix(deps): update dependency known-css-properties to ^0.33.0 (#153)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

804 of 959 branches covered (83.84%)

Branch coverage included in aggregate %.

1243 of 1359 relevant lines covered (91.46%)

56.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.21
/lib/utils/ast-utils/utils.ts
1
import type { Rule, Scope } from "eslint";
2
import * as eslintUtils from "@eslint-community/eslint-utils";
1✔
3
import type {
4
  Expression,
5
  Identifier,
6
  Literal,
7
  MemberExpression,
8
  MethodDefinition,
9
  Node,
10
  PrivateIdentifier,
11
  Property,
12
  PropertyDefinition,
13
  TemplateElement,
14
  TemplateLiteral,
15
} from "estree";
16

17
/**
18
 * Get a parent node
19
 * The AST node used by ESLint always has a `parent`, but since there is no `parent` on Types, use this function.
20
 */
21
export function getParent<E extends Node>(node: Node | null): E | null {
1✔
22
  if (!node) {
384!
23
    return null;
×
24
  }
25
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore
26
  return (node as any).parent;
384✔
27
}
28

29
/**
30
 * Find the variable of a given name.
31
 */
32
export function findVariable(
1✔
33
  context: Rule.RuleContext,
34
  node: Identifier,
35
): Scope.Variable | null {
36
  return eslintUtils.findVariable(getScope(context, node), node);
38✔
37
}
38

39
/**
40
 * Get the value of a given node if it's a constant of string.
41
 */
42
// export function getStringIfConstant(
43
//     context: Rule.RuleContext,
44
//     node: Node,
45
// ): string | null {
46
//     return eslintUtils.getStringIfConstant(node, getScope(context, node))
47
// }
48

49
/**
50
 * Get the property name of a given nodes.
51
 */
52
export function getPropertyName(
1✔
53
  context: Rule.RuleContext,
54
  node: MemberExpression | MethodDefinition | Property | PropertyDefinition,
55
): string | null {
56
  return eslintUtils.getPropertyName(node, getScope(context, node));
16✔
57
}
58
type GetStaticValueResult =
59
  | { value: unknown }
60
  | { value: undefined; optional?: true };
61

62
/**
63
 * Get the value of a given node if it's a static value.
64
 */
65
export function getStaticValue(
1✔
66
  context: Rule.RuleContext,
67
  node: Node,
68
): GetStaticValueResult | null {
69
  return eslintUtils.getStaticValue(node, getScope(context, node));
6✔
70
}
71

72
/**
73
 * Gets the scope for the current node
74
 */
75
export function getScope(
1✔
76
  context: Rule.RuleContext,
77
  currentNode: Node,
78
): Scope.Scope {
79
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore
80
  const scopeManager: Scope.ScopeManager = (context.getSourceCode() as any)
60✔
81
    .scopeManager;
82

83
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore
84
  let node: any = currentNode;
60✔
85
  for (; node; node = node.parent || null) {
60!
86
    const scope = scopeManager.acquire(node, false);
318✔
87

88
    if (scope) {
318✔
89
      if (scope.type === "function-expression-name") {
60!
90
        return scope.childScopes[0];
×
91
      }
92
      return scope;
60✔
93
    }
94
  }
95

96
  return scopeManager.scopes[0];
×
97
}
98

99
/**
100
 * Find expression node
101
 */
102
export function findExpression(
1✔
103
  context: Rule.RuleContext,
104
  id: Identifier,
105
): Exclude<Expression, Identifier> | null {
106
  let target: Expression = id;
13✔
107

108
  const set = new Set<Identifier>();
13✔
109
  while (target.type === "Identifier") {
13✔
110
    if (set.has(target)) {
15✔
111
      return null;
1✔
112
    }
113
    set.add(target);
14✔
114
    const variable = findVariable(context, target);
14✔
115
    if (!variable) {
14!
116
      return null;
×
117
    }
118
    if (variable.defs.length !== 1) {
14✔
119
      return null;
1✔
120
    }
121
    const def = variable.defs[0];
13✔
122
    if (
13✔
123
      def.type !== "Variable" ||
38✔
124
      def.parent.kind !== "const" ||
125
      !def.node.init
126
    ) {
127
      return null;
1✔
128
    }
129
    target = def.node.init;
12✔
130
  }
131

132
  return target;
10✔
133
}
134

135
/**
136
 * Checks whether given node is static template literal
137
 */
138
export function isStaticTemplateLiteral(
1✔
139
  node: Expression | PrivateIdentifier,
140
): node is TemplateLiteral & { quasis: [TemplateElement]; expressions: [] } {
141
  return node.type === "TemplateLiteral" && node.quasis.length === 1;
13✔
142
}
143
/**
144
 * Checks whether given node is string literal
145
 */
146
export function isStringLiteral(
1✔
147
  node: Expression | PrivateIdentifier,
148
): node is Literal & { value: string } {
149
  return node.type === "Literal" && typeof node.value === "string";
6✔
150
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc