-
Notifications
You must be signed in to change notification settings - Fork 13
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
Typing and code improvements #1037
Labels
Improvement
Surface improvement to API, code, QoL, …
Comments
D extends Diagnostic
type parameter to alfa-act
Merged
This was referenced Apr 13, 2023
Merged
This was referenced May 1, 2023
Merged
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Typing, type safety, modularity, …
Remove
Err#get
andOk#getErr
Add
getUnsafe
instead.Consider storing string literals duplicated in multiple places as string constants, like URLs like
"about:blank"
Export
Diagnostic
subclasses fromalfa-rules
, not just theis*
functions.Add
Maybe.toOption
or similar way to convert fromMaybe
toOption
Adding a
D extends Diagnostic
to rulesMost classes in
alfa-act
wrap aDiagnostic
(Outcomes
,Question
), or will produce one (Rule
). We should add a type parameterD extends Diagnostic
to these and make sure it is correctly propagated.This would ensure better type safety for consumers. Among other, if we change the specific diagnostic produced by a rule, a consumer with old code of an
Outcome<… D …>
(produced by aRule<… D …>
) would cause type mismatch when trying to consume anOutcome<… D' …>
and avoid runtime error by trying to access fields that have changed.We might even be able to have several diagnostic parameters for rules and separate based on which outcome is produced.
Collection
predicates (every
, …) should acceptRefinement
, not justPredicate
; also need to be done forArray
.Add a
Teeable
type for type who support.tee(callback)
, probably requireFunctor
,Applicative
, and extended types to also extendTeeable
.Use
import type
where relevant to limit risks of circular imports (and make the intend obvious).Use
exports
maps inpackage.json
files to force restrict the exposed API and enforce ADR 7. See package entry points.Export
Question.Data
fromalfa-rules
so it can be used by consumers (e.g. access the list of URI as a value, not just a type).CSS polish and
Math
supportRework the registering of properties in a more straightforward way; should allow to update to TS 5.
Add proper hashing to CSS
Math
expressionsCurrently doing nothing, need to hash
Expression
so that we can hashCalculation
correctly.CSS
Math
expressions that are reduced to aValue
should be turned intoCSSValue(…)
rather thanMath(Value(…))
Create an abstraction for
Length | Math
value (plus resolver) (same with other numeric types and combination with percentages). Maybe inalfa-style
if notalfa-css
. This would effectively solve Supportcalc()
expressions in all properties #1202.API improvements
Turn
isNone
,isSome
, … into getters?Or even into properties to avoid the function call altogether, although it is fairly inexpensive…
We could have
Open
andClose
be parametric in the type of delimiter (Open<Parenthesis>
, …), likely with anEnum
somewhere. That would enable us to have the type system enforce matching open and close delimiters.alfa/packages/alfa-css/src/syntax/block.ts
Lines 87 to 98 in 24de3ed
Had a wrapper
Option = None | Some
type so that!foo.isNone()
correctly narrows toSome
.Factor in a
getElementById
or equivalent, so we can cache the map; it is currently used when looking foraria-owns
, when looking foraria-labelledby
, and when looking for ID ref list attributes in R19.Replace usages of
elementDescendants()
withQuery.getElementDescendants()
Polishing code, unifying standards
Tests clean-up
Many tests on attributes use a
const target = element.attribute("foo").getUnsafe()
structure that could be build bottom-up instead.We have a lot of rules targeting the full document using the same pattern:
and it seems to be our main use of both
hasChild
andisDocumentElement
.We should make a
getDocumentElement
helper to capture this pattern, likely of typeDocument => Option<Element>
.hasDisplaySize
should have proper overloads.hasInlineStyleProperty
could be overloaded to also acceptPredicate<Property.Name>
, and severalProperty.Name
(pass if all are declared instyle
).hasTextContent
could be overloaded to accept a list of strings (pass if one of them exactly matches the text content).hasTabIndex
could be overloaded to accept a list of numbers (pass if the tabindex is one of those)isIncludedInTheAccessibilityTree = not(isIgnored)
could be introduced since it matches the rules better, and is how it's used most of the time. We might even want to get rid ofisIgnored
and directly writeisIncludedInTheAccessibilityTree
(inlining the negation).Remove useless layer of empty arg from
hasUniqueId
(turn it from avoid => Predicate<Element>
to aPredicate<Element>
, akaElement => boolean
).Not doable as they depend ongetOffsetParent
: move definition ofisStatic
andisFixed
together withisBody
andisTabular
.device
.R75 expectation could use both
hasCascadedStyle
andhasComputedStyle
(and may need ahasSpecifiedStyle
to be really clean).isPerceivable
can usehasInclusiveDescendant
.Go through all the parsers in
alfa-css
to see if they can be simplified and rewritten in terms of other parsers likedelimited
,option
etc.Consider moving optional parameters into an options object or similar in
alfa/packages/alfa-dom/src/h.ts
Lines 36 to 38 in e7eaf8e
Consider returning
Result
rather thanOption
in case of missing layout: Use layout to improve handling of interposed elements #1464 (comment)Incorporate
WithFirstHeading
intoWithOtherHeading
:alfa/packages/alfa-rules/src/sia-r61/rule.ts
Line 83 in 77cdcc8
Done
alfa-rules/Flattened.Rule
is ill namedThe union type of all rules (currently
Flattened.Rule
) should be moved out of theFlattened
namespace. The flattened type of a rule (currentlyact.Rule<Input, Target, Question, Subject>
) should instead beFlattened.Rule
(with the union moved on the parameters).isTransparent
can usehasComputedStyle
.isInert
could usehasComputedStyle
.R71, R72, R85 could use
hasComputedStyle
.R74, R80 could likely use
hasCascadedStyle
.Updating to TS ⩾ 4.8.3 should let us clean https://github.com/Siteimprove/alfa/blob/main/packages/alfa-dom/src/jsx.ts#L34-L36
Proper hash of
Outcome
Hide access to underlying array of
Slice
to avoid incorrect usage.Slice
already exposes the necessary functionality for reading likeget
,first
,rest
etc. so no direct access to the underlying array should ever be needed. In particular thearray
property should not be visible and potentially we should not exposeoffset
as well:alfa/packages/alfa-slice/src/slice.ts
Lines 48 to 54 in 7c45b01
The text was updated successfully, but these errors were encountered: