Commit graph

98 commits

Author SHA1 Message Date
Jelle van der Waa
db420e6eae eslintrc: Enable eqeqeq
Resolves: COCKPIT-1910
2026-11-03 17:37:17 +01:00
Jelle van der Waa
618473f951 package.json: Switch to markdown-to-jsx
The PackageKit UpdateDetail signal provides markdown in the
`update_text` and uses remarkable to parse the markdown contents.

Remarkable however has not been updated since 6 years, additionally it
requires us to use `dangerouslySetInnerHTML` which can lead to XSS
issues.

The npm ecosystem has two other markdown alternatives `react-markdown`
and a `markdown-to-jsx`. The latter has zero dependencies while
`react-markdown` has eleven and requires additional plugins like
`rehype-external-links` to add a rel/target to external links.

https://www.freedesktop.org/software/PackageKit/gtk-doc/Transaction.html
https://github.com/jonschlinkert/remarkable/issues/438
2026-10-09 15:43:36 +02:00
Marius Vollmer
8d178e856e build: Allow TS functions to be used before their definition
This is fine, TypeScript will check them correctly.  And it is very
useful for global functions, at least.  And we allow functions to be
used before their definitions in JavaScript files.
2024-11-14 10:57:54 +02:00
Marius Vollmer
9601aee69e build: Use "projectService" instead of "project" for eslint
Because magic.

Fixes #21246
2024-11-11 14:30:14 +02:00
Allison Karlitskaya
8bba86476e .eslintrc.json: setup some TypeScript rules
- disable the base no-use-before-define rule: it doesn't understand
   that TypeScript allows using types before they're defined.  Enable
   the TypeScript-specific rule for it for TypeScript files.

 - add an 'unused variables' config matching the default rules of the
   TypeScript compiler

Both of these rule stanzas were copied from the documentation of the
typescript-eslint plugin.  Links to those pages are provided in
comments, which are valid in the extended JSON syntax used for eslintrc.

Tweak our test/static-code rule for JSON to also exempt eslintrc from
our strict checking.
2024-07-18 06:33:31 +02:00
Jelle van der Waa
07fd7c2d8b .eslintrc.json: boolean values are deprecated for globals
As per ESLint docs these options still allow boolean values but in
reality they are deprecated and replaced by "readonly". Oxlint currently
cannot deal with this and therefore cannot parse the eslint
configuration file.

https://eslint.org/docs/latest/use/configure/language-options#using-configuration-files
2024-05-21 13:15:31 +02:00
Jelle van der Waa
ea6846753b eslint: enable no-useless-fragment rule by default
This rule is not part of the standard ESLint recommends set but is
useful and can be auto-fixed.
2024-04-23 00:13:38 +02:00
Allison Karlitskaya
9f7bd38b61 test/static-code: add support for typescript
Add the typescript compiler to our devel dependencies and run it from
`test/static-code`.  We add an initial cockpit.d.ts and a tsconfig.json
which will get `tsc` to report errors against any `.ts` or `.tsx` files.
2024-04-10 19:51:25 +02:00
Katerina Koukiou
fe89f2eff5 build.js: Move our front end build tool from webpack to esbuild
We don't need the `$ESLINT`/`$STYLELINT` env variables any more to
coordinate between build.js and webpack-config.js, as everything is in
build.js now. Update HACKING.md accordingly.

Implement our own watch mode due to the deficiencies of esbuild's [1].
This is similar to podman's [2], but with recursive watching.

Because the approach for redefining breakpoints changed, update pixel
tests for the spacing noise.

Co-Authored-By: Martin Pitt <mpitt@redhat.com>

Fixes #17629

[1] https://github.com/evanw/esbuild/issues/1204#issuecomment-1482909251
[2] https://github.com/cockpit-project/cockpit-podman/pull/1243
2023-03-27 15:22:36 +02:00
Martin Pitt
3ca1569f82 pkg: Avoid webpack-loader syntax
This is discouraged. Replace these imports with a webpack rule, and
re-enable the `import/no-webpack-loader-syntax` ESLint rule.

This will make our code compatible with esbuild.
2023-03-16 15:57:11 +01:00
Katerina Koukiou
097f93cfe1 Bump eslint version
Autofix warnings: Expected property shorthand
2023-02-27 23:53:02 +01:00
Jelle van der Waa
58b95f1a8c pkg: make JavaScript keyspacing consistent
cockpit-ostree enables this by default and we have to disable it now.
Having consistent key spacing for all our JavaScript objects seems like
something we want everywhere as eslint --fix can automatically.
2022-11-09 15:37:56 +01:00
Jelle van der Waa
e95a18156e pkg: enable object property newline rule
This is more readable and automatically applied using `eslint --fix`.
2022-11-08 22:13:33 +01:00
Allison Karlitskaya
fe5f5be98e eslintrc: allow 3 chained calls on one line
We have some semi-reasonable patterns of code which chain 3 calls on a
single line.  Unfortunately there doesn't seem to be a way to
distinguish between chaining for promises and for other things (like
text manipulation).  Line length can be a proxy for that, though.
2022-03-29 15:52:33 +02:00
Katerina Koukiou
d7c6c14be1 eslintrc: reenable array callback return rule and fix all related errors
Reasoning:
A map() creates an array, so a return is expected for all code paths (if/elses).
If one does not want an array or to return data, they should use forEach instead.
Similar for filter().

An expection in our codebase was cockpit.transport.filter which confused
the linter, thinking that its an array filter. I disabled linting on these
lines for this rule.
2022-03-29 14:13:36 +02:00
Katerina Koukiou
9e21feac9c package.json: remove unused expose-loader and update eslint-config-standard
expose-loader
-------------
Commit removing it's last usage point was: c3533e5799

eslint
------
Update eslint-config-standard to next major version

This enables multiline-ternary rule, which gives many:
error  Expected newline between consequent and alternate of ternary expression  multiline-ternary

Fix this automatically with npm run eslint:fix

Also temporarily disable array-callback-return rule, which was also
enabled in this config version, and gives a lot of (actually valid)
errors. Make sure to enable it in follow up commit.

Lastly fix single occurance of:
error  Use a regular expression literal instead of the 'RegExp' constructor  prefer-regex-literals
2022-03-29 14:13:36 +02:00
Katerina Koukiou
3d4a10409f eslintrc: remove jsx-a11y from the plugins section
As we are already extending the recommended settings without
modifications.
2022-03-29 14:13:36 +02:00
Katerina Koukiou
b3347ab4bc eslintrc: extend recommended configuration of flowtype plugin
Previously it was in the section for customized rules, but not rules
were specified, resulting in this not taking any effect.
2022-03-29 14:13:36 +02:00
Matej Marusak
5608bca65d shell: Disable no-autofocus rule
We need to focus password input first. There are no active elements
preceding this input.

Fixes #12954
2022-01-20 10:57:28 +01:00
Matej Marusak
2c1d8b603c Use buttons instead of anchor elements
This works around this a11y rule. We use it correctly, but due to the
way Cockpit navigates eslint was complaining.

Also since I changed style of our tabs, I styled to look exactly as
`<Tabs>` event though we use `<Nav>` as tabs (due to issues on mobile).
2022-01-20 10:57:28 +01:00
Martin Pitt
ba8700a6e5 eslint: Enable no-var rule
`var` has broken/unexpected scoping in JavaScript, and can lead to
subtle errors. It's preferable and safer to use `const` whenever
possible, and `let` where necessary.

Most pages got updated by now, so let's make sure they stay that way.
Disable the rule for the four remaining known pages which still use
`var`. Also temporarily downgrade the `error` to `warn` when running
`npm run eslint`, as that is covered by the unit-tests "distcheck"
scenario. This requires touching package.json and thus a node_modules
rebuild.
2021-09-22 12:48:34 +02:00
Martin Pitt
98e1168b31 base1: Drop cockpit.all()
cockpit.all() was deprecated over two years ago in commit f83c353d86,
and was never documented API. Nothing uses it any more.

Also drop our custom eslint plugin, it has served its purpose.
2021-04-30 09:34:11 +02:00
Martin Pitt
c84c3dbfb6 Use current babel/eslint integration
Fixes these `npm install` warnings:

> deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
> deprecated eslint-loader@4.0.2: This loader has been deprecated. Please use eslint-webpack-plugin

Cherry-picked from starter-kit commit 0e608d562a.
2021-04-12 09:34:03 +02:00
Martin Pitt
f5e709ca60 npm: Upgrade eslint to current major versions
Cherry-picked from starter-kit commit 8f93db223476.

The new `react/jsx-wrap-multilines` rule looks desirable, but that might
not be unanimous. Disable it for now and postpone for a follow-up.
2021-04-12 09:34:03 +02:00
Katerina Koukiou
c52df10b5a eslint: enable noonchange rule 2021-04-11 09:04:07 +02:00
Matej Marusak
2da6904316 a11y: Enable jsx-a11y rule
Nothing breaks it anymore.
2021-02-23 07:17:17 +01:00
Matej Marusak
4fb3ec76a7
users: Make users list correctly accessible
Lets use <ul> and <li> since it is actually list.
Also use 'role="presentation"' to indicate that the box itself has no
semantic meaning, it just is wrapper that catches events when user click
anywhere on the box.

Also did one small change for sliders in storage where I added
'role="presentation"' so it is not used in a11y tree. We always have
input next to this slider for it to be accessible. Making fully
accessible slider is not that complicated, but the goal with our sliders
always was that they are ignored when using keyboard and users will just
use inputs.

That also makes it possible to enforce another a11y jsx rule.

Closes #14091
2020-05-18 12:13:23 +02:00
Matej Marusak
b23f8db9e6
Fix keyboard navigation
This rule is actually very useful, as it points to things, that are not
keyboard navigable. We were introducing new breakages since we disabled
this rule (like services and overview pages).

Here is list of things that did not work before, but do now:

- service-tabs.jsx: The whole navigation (targets, sockets...) was not
reachable by keyboard.

- page-status.jsx: Items in 'Health' card were reachable by keyboard,
but could not be activated by keyboard.

- usageCard.jsx: Text 'View graphs' on 'Usage' card was reachable by
keyboard, but could not be activated by keyboard.

- systemInformationCard.jsx: Text 'View hardware details' on 'System information'
card was reachable by keyboard, but could not be activated by keyboard.

- insights.jsx: Text 'Not connected to Insights' on 'Health' card was reachable
by keyboard, but could not be activated by keyboard.

- storage-controls.jsx: The 'things' menu on storage page could be
opened by keyboard, but the elements inside were not reachable by keyboard.

- overview.jsx: On storage page non of 'Devices', Drives'... and any
other devices were not reachable by keyboard. Now they are reachable and
also it is possible to activate them by keyboard. (This includes also
'Show all' buttons)

- diskEdit.jsx: These prevents were pointless so I dropped them.
Otherwise we would need to do the same for keyboard events.

- containers-view.jsx: Items could not be activated with keyboard.

- cockpit-components-listing.jsx: Give the event listener to appropriate element.

- fsys-tab.jsx: This is actually unused but making it link-styled button
seems like a correct approach to make it accessible.

Part of #12954
Closes #13996
2020-05-04 11:24:01 +02:00
Matej Marušák
cf6ecb9aad a11y: Every label tag needs an associated control
Closes #13070
2019-11-05 07:07:31 +01:00
Matej Marušák
b9c11cc073 a11y: Every image must have an alt attribute
When the image is purely decorative, then `alt=''` is acceptable.

Closes #13069
2019-10-31 08:44:13 +01:00
Martin Pitt
4b102824ac build: Add eslint rules for React hooks
These make components with simple state (only a few variables) easier to
read and maintain. See https://reactjs.org/docs/hooks-intro.html for
details. Hook are available since React 16.8, and we already depend on 16.10.

We don't have any hooks yet in our code. This enables the ESLint plugin
to guide us right from the start.
2019-10-18 14:52:34 +02:00
Matej Marusak
5ed5dfcb31 tuned: Drop unused class
It is not used anywhere and it just makes linter unhappy.
2019-10-10 13:18:36 +03:00
Matej Marusak
3fe6dfe1c0 eslint: Introduce jsx-a11y plugin
Closes #12854
2019-10-10 13:18:36 +03:00
Matej Marusak
0cc322e362 eslint: Check that elements have key prop in arrays and arrow functions
Closes #12855
2019-09-21 12:17:41 +02:00
Matej Marusak
92875a13ce Fix and enforce noopener noreferrer on target=_blank
See https://www.jitbit.com/alexblog/256-targetblank---the-most-underestimated-vulnerability-ever/

Also prefer `rel` to `referrerpolicy` since it is much better supported:
https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/rel
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy

Closes #12767
2019-09-11 16:09:02 +02:00
Matej Marusak
6c97c622df package.json: Bump up version of eslint
Disable rules that need complex fixing, these should be fixed as
follow-ups.

First three should really be fixed, the rest is not that important.

Closes #12644
2019-08-30 10:25:38 +02:00
Matej Marusak
4d07fed4ea .eslintrc.json: Change from react:latest to react:detect
In this case it picks the version we use. (latest was picking up
something older than 16.2)
2019-08-30 10:25:38 +02:00
Sanne Raymaekers
992a49323f eslintrc: Set "root" to true
Eslint shimmies up directories looking for more eslintrcs. As
make-checkout now clones projects in a subdirectory, this can result in
some strange interactions.

Each subproject using eslint should enable this as well.

https://eslint.org/docs/user-guide/configuring

Closes #12610
2019-08-26 13:17:39 +02:00
Martin Pitt
8e956fcc40 Move to latest eslint
This fixes deprecation warnings about
`parserOptions.ecmaFeatures.experimentalObjectRestSpread`.

Closes #11124
2019-02-07 19:00:39 +01:00
Lars Karlitski
c5868236fb eslint: Add a rule to disallow using cockpit.all()
cockpit.all() is deprecated and should not be used in new code.

Add an eslint exception and a comment to all call sites for which using
Promise.all() is not yet possible (see previous commit).

Closes #10949
2019-01-15 08:25:11 +01:00
Martin Pitt
560095f856 eslint: Disable "no-template-curly-in-string" rule
These are false positives, as we often use i18n like

    cockpit.format(_("foo ${bar}"), ...)

where we do want curly formats in strings.
2018-11-23 17:48:38 +01:00
Katerina Koukiou
1ec0c0738a eslint: Mute warning about missing react version
Previously we were seeing the following error when running eslint.
Warning: React version not specified in eslint-plugin-react settings. See https://github.com/yannickcr/eslint-plugin-react#configuration.

Closes #10147
2018-09-25 09:19:25 +02:00
suomiy
53ea9be5a2 eslint: Enable "semi" rule
Fix semicolons in all files.

Closes  #9736
2018-07-26 21:58:41 +02:00
suomiy
ea788ab443 eslint: Enable "lines-between-class-members" rule
Closes #9694
2018-07-20 12:35:37 +02:00
Martin Pitt
ea516f0851 eslint: Enable "prefer-promise-reject-errors" rule
See https://eslint.org/docs/rules/prefer-promise-reject-errors for
rationale.

Closes #9168
2018-05-15 11:03:22 +03:00
Martin Pitt
87deca1c38 eslint: Enable "handle-callback-err" rule 2018-05-15 11:03:22 +03:00
Martin Pitt
50aa6ad0c9 eslintrc: Permanently disable "standard/no-callback-literal" rule
It was previously in the "desirable to turn on" section, but it
complains about valid code and is considered to be removed:
https://github.com/standard/eslint-plugin-standard/issues/27
2018-05-15 11:03:22 +03:00
Martin Pitt
945e288630 eslint: Enable "new-cap" rule
`cockpit.defer()` is not meant to be instantiated with `new`.
2018-05-15 11:03:22 +03:00
Martin Pitt
5d83d2821b eslint: Enable "no-throw-literal" rule
This provides proper stack traces on errors.
2018-05-15 11:03:22 +03:00
Martin Pitt
bfe401a8da eslint: Enable "no-extra-boolean-cast" rule
Closes #9121
2018-05-07 12:07:03 +02:00