mirror of
https://github.com/github/codeql.git
synced 2026-05-01 19:55:15 +02:00
Swift: remove now unused ql.Property.params
This commit is contained in:
@@ -8,7 +8,6 @@ import inflection
|
||||
@dataclass
|
||||
class Param:
|
||||
param: str
|
||||
type: str = None
|
||||
first: bool = False
|
||||
|
||||
|
||||
@@ -19,16 +18,11 @@ class Property:
|
||||
tablename: str
|
||||
tableparams: List[Param]
|
||||
plural: str = None
|
||||
params: List[Param] = field(default_factory=list)
|
||||
first: bool = False
|
||||
local_var: str = "x"
|
||||
is_optional: bool = False
|
||||
|
||||
def __post_init__(self):
|
||||
if self.params:
|
||||
self.params[0].first = True
|
||||
while self.local_var in (p.param for p in self.params):
|
||||
self.local_var += "_"
|
||||
assert self.tableparams
|
||||
if self.type_is_class:
|
||||
self.tableparams = [x if x != "result" else self.local_var for x in self.tableparams]
|
||||
|
||||
@@ -25,7 +25,6 @@ def get_ql_property(cls: schema.Class, prop: schema.Property):
|
||||
type=prop.type,
|
||||
tablename=inflection.tableize(f"{cls.name}_{prop.name}"),
|
||||
tableparams=["this", "index", "result"],
|
||||
params=[ql.Param("index", type="int")],
|
||||
is_optional=prop.is_optional,
|
||||
)
|
||||
elif prop.is_optional:
|
||||
@@ -58,8 +57,6 @@ def get_types_used_by(cls: ql.Class):
|
||||
yield b
|
||||
for p in cls.properties:
|
||||
yield p.type
|
||||
for param in p.params:
|
||||
yield param.type
|
||||
|
||||
|
||||
def get_classes_used_by(cls: ql.Class):
|
||||
|
||||
@@ -5,31 +5,11 @@ from swift.codegen.lib import ql
|
||||
from swift.codegen.test.utils import *
|
||||
|
||||
|
||||
def test_property_has_first_param_marked():
|
||||
params = [ql.Param("a", "x"), ql.Param("b", "y"), ql.Param("c", "z")]
|
||||
expected = deepcopy(params)
|
||||
expected[0].first = True
|
||||
prop = ql.Property("Prop", "foo", "props", ["this"], params=params)
|
||||
assert prop.params == expected
|
||||
|
||||
|
||||
def test_property_has_first_table_param_marked():
|
||||
tableparams = ["a", "b", "c"]
|
||||
prop = ql.Property("Prop", "foo", "props", tableparams)
|
||||
assert prop.tableparams[0].first
|
||||
assert [p.param for p in prop.tableparams] == tableparams
|
||||
assert all(p.type is None for p in prop.tableparams)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("params,expected_local_var", [
|
||||
(["a", "b", "c"], "x"),
|
||||
(["a", "x", "c"], "x_"),
|
||||
(["a", "x", "x_", "c"], "x__"),
|
||||
(["a", "x", "x_", "x__"], "x___"),
|
||||
])
|
||||
def test_property_local_var_avoids_params_collision(params, expected_local_var):
|
||||
prop = ql.Property("Prop", "foo", "props", ["this"], params=[ql.Param(p) for p in params])
|
||||
assert prop.local_var == expected_local_var
|
||||
|
||||
|
||||
def test_property_not_a_class():
|
||||
|
||||
@@ -18,7 +18,6 @@ ql_output_path = lambda: paths.swift_dir / "ql/lib/other/path"
|
||||
import_file = lambda: stub_path().with_suffix(".qll")
|
||||
stub_import_prefix = "stub.path."
|
||||
gen_import_prefix = "other.path."
|
||||
index_param = ql.Param("index", "int")
|
||||
|
||||
|
||||
def generate(opts, renderer, written=None):
|
||||
@@ -121,7 +120,7 @@ def test_repeated_property(opts, input, renderer):
|
||||
import_file(): ql.ImportList([stub_import_prefix + "MyObject"]),
|
||||
stub_path() / "MyObject.qll": ql.Stub(name="MyObject", base_import=gen_import_prefix + "MyObject"),
|
||||
ql_output_path() / "MyObject.qll": ql.Class(name="MyObject", final=True, properties=[
|
||||
ql.Property(singular="Foo", plural="Foos", type="bar", tablename="my_object_foos", params=[index_param],
|
||||
ql.Property(singular="Foo", plural="Foos", type="bar", tablename="my_object_foos",
|
||||
tableparams=["this", "index", "result"]),
|
||||
])
|
||||
}
|
||||
@@ -135,7 +134,7 @@ def test_repeated_optional_property(opts, input, renderer):
|
||||
import_file(): ql.ImportList([stub_import_prefix + "MyObject"]),
|
||||
stub_path() / "MyObject.qll": ql.Stub(name="MyObject", base_import=gen_import_prefix + "MyObject"),
|
||||
ql_output_path() / "MyObject.qll": ql.Class(name="MyObject", final=True, properties=[
|
||||
ql.Property(singular="Foo", plural="Foos", type="bar", tablename="my_object_foos", params=[index_param],
|
||||
ql.Property(singular="Foo", plural="Foos", type="bar", tablename="my_object_foos",
|
||||
tableparams=["this", "index", "result"], is_optional=True),
|
||||
])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user