linter icon indicating copy to clipboard operation
linter copied to clipboard

Investigate new `sort_child_properties_last` diagnostics when relaxed

Open pq opened this issue 4 years ago • 5 comments

#2648 introduces new diagnostics to libraries in (at least) 20 internal packages (the SDK roller stopped trying to add exceptions at 20). We'll need to investigate if these are false positives or if we need to coordinate fixes before the next roll.

/cc @a14n @emmanuel-p @jacob314

pq avatar Jun 15 '21 14:06 pq

Example breakage:

  @override
  Widget build(BuildContext context) => Scaffold(
      appBar: AppBar(
        brightness: widget.brightness,
        leading: IconButton(
          icon: const BackButtonIcon(), // <= LINT
          tooltip: MaterialLocalizations.of(context).backButtonTooltip,
          onPressed: () {
             ...
          },
          key: backButton,
        ),
       title: TextField(
          autofocus: true,
          style: widget.inputStyle ??
              TextStyle(
                 ...
              ),
          decoration: InputDecoration.collapsed(
            hintText: widget.hintText,
            hintStyle: TextStyle(color: Colors.grey[500]),
          ),
          controller: _controller,
        ),
        actions: <Widget>[ // <= LINT
          _controller.text != ''
              ? IconButton(
                  icon: Icon(
                    Icons.cancel,
                    color: Colors.grey[500],
                  ),
                  tooltip: AutocompleteLocalizations.of(context)!.clearLabel(),
                  onPressed: () => _controller.text = '',
                  key: clearButton,
                )
              : Container()
        ],
        backgroundColor: widget.appBarColor,


  ...

pq avatar Jun 15 '21 14:06 pq

This need to be fixed as the lint checks now all Widget arguments and not only child/children (this was requested as part of a review on #2714)

a14n avatar Jun 15 '21 15:06 a14n

Good to know. Given the impact, we'll have to come up with a plan for migration (or reconsider the additional diagnostics).

Thanks!

/fyi @jacob314

pq avatar Jun 15 '21 15:06 pq

Happy to help migrate. Perhaps it would be worth it to add a quick fix to help migrate? Moving all violating properties to after the last non-child & non closure property would probably be a fine default. In the example given, backgroundColor should be at the top of the method next to the brightness property. As is it is, it takes a while to spot what widget the backgroundColor is associated with.

jacob314 avatar Jun 15 '21 16:06 jacob314

Perhaps it would be worth it to add a quick fix to help migrate?

FWIW there is a fix but I expect it will need to be updated w/ the new and improved semantics.

pq avatar Jun 15 '21 16:06 pq