Commit Graph

33 Commits

Author SHA1 Message Date
Florian Müllner
4fbd878208 lint: Sync with gnome-shell
gnome-shell itself no longer requires parameter descriptions in
doc comments (just type annotations). The requirement makes even
less sense for extensions, so sync up the configuration.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/276>
2023-09-26 14:30:27 +02:00
Florian Müllner
b7f285d733 Make project compatible with Reuse Software spec
Provide all licenses used in the project in a LICENSES folder and
add SPDX license and copyright information for all files in
accordance with the Reuse Software[0] specification.

The copyright information is based on the file's git history,
using a fairly generous definition of "non-trivial".

As of the spec recommendation, the information is generally added
as comments in the files themselves, except for

 - NEWS, README and similar top-level standard files, so that
   a SPDX code isn't the first thing people encounter
 - files that don't support comments (json) or where they'd
   be a bit awkward (.desktop, .service)
 - anything under po/, to not interfere with translation teams

Those are covered by a .reuse/dep5 files, except for image assets,
where separate .license files are used (It would be possible to
add comments to SVG files, but I don't trust image editors to
preserve them).

[0] https://reuse.software/

Part-of:
<https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/224>
2023-08-17 11:51:48 +00:00
Florian Müllner
cf007dd472 extensions: Turn extensions into modules
As gnome-shell is moving to ESM, it will now load extensions as
standard modules instead of using legacy imports. The change boils
down to exporting the Extension class as default, but we can also
start using standard imports for introspected modules now, so do
that at the same time.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/259>
2023-07-07 00:35:08 +02:00
Florian Müllner
18674b2e35 lint: Migrate eslint-plugin-jsdoc rule
Migrate a removed jsdoc, copied from the corresponding gnome-shell
change.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/259>
2023-07-07 00:11:57 +02:00
Florian Müllner
563d7770d3 lint: Sync with gnome-shell
gnome-shell started transitioning to gjs' object spacing rule,
i.e. `{foo: 42}` instead of `{ foo: 42 }`.

We have a much smaller code base than the shell and aren't using
a secondary "allowed-but-deprecated" configuration that allows a
gradual transition, so just pull the switch and update to the new
style.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/240>
2022-08-20 19:00:32 +02:00
Florian Müllner
b35df9062c lint: Sync with gjs
This is needed for eslint to recognize static class blocks.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/215>
2022-02-18 03:34:06 +00:00
Florian Müllner
8f362d57fe lint: Synchronize configuration with gjs
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/180>
2021-08-13 04:57:35 +02:00
Florian Müllner
72c67aacc4 lint: Sync configuration with gjs
gjs updated its eslint configuration, so sync our copy.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/137
2020-11-14 00:58:52 +01:00
Florian Müllner
2655419880 lint: Sync configuration with gjs
gjs updated its eslint configuration to a much more complete and
thorough set.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/91
2019-08-21 15:13:43 +00:00
Florian Müllner
85fa282153 lint: Convert eslint JSON to YAML
gjs will change its configuration to YAML, so switch to that format
to keep syncing possible.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/90
2019-08-14 16:34:45 +00:00
Florian Müllner
6a25971366 lint: Also allow camelcase for default signal handlers
on_some_signal() is used less than vfunc_some_method(), but it can
still be useful.
2019-07-02 02:44:22 +02:00
Florian Müllner
dc3523a344 lint: Remove misleading globals
While those are defined by gnome-shell, we generally want to define our
own with the correct gettext domain.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/79
2019-06-29 03:07:56 +02:00
Florian Müllner
25e43a5d08 lint: Remove legacy configuration
After the last batch of indentation changes, the whole code base
conforms to the new style now, so we can drop the legacy eslint
configuration.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/66
2019-05-22 20:40:19 +02:00
Florian Müllner
6e63edd737 lint: Sync with gjs
Some of our custom rules have been upstreamed[0], update the
rule sets accordingly.

[0] https://gitlab.gnome.org/GNOME/gjs/merge_requests/272
https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/59
2019-03-03 05:54:58 +01:00
Florian Müllner
d83d6e857a style: Use single-quotes for translated strings
The coding style of using double quotes for translatable strings
and single quotes otherwise is unnecessarily complex and cannot
be enforced with an eslint rule.

Simply use single quotes consistently for all strings.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/57
2019-02-28 23:29:31 +01:00
Florian Müllner
db35d7ae7c style: Change indentation style of object literals
Instead of keeping the first property on the same line as the opening
brace and aligning the properties, use a four-space indent. This brings
us closer to gjs' coding style, and as a bonus helps keeping lines in
the soft 80 character limit.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/57
2019-02-28 23:29:24 +01:00
Florian Müllner
d34b5030b9 style: Use a consistent style for array literals
Most array literals already use a four-space indent, except the ones in
GObject metainfo and function parameters. Reindent those as well to make
the style consistent and bring it closer to gjs' coding style.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/57
2019-02-28 23:29:14 +01:00
Florian Müllner
7f8f1234ae style: Stop using braces for single-line arrow functions
Braces are optional for single-line arrow functions, but there's a
subtle difference:
Without braces, the expression is implicitly used as return value; with
braces, the function returns nothing unless there's an explicit return.

We currently reflect that in our style by only omitting braces when the
function is expected to have a return value, but that's not very obvious,
not an important differentiation to make, and not easy to express in an
automatic rule.

So just omit braces consistently as mandated by gjs' coding style.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/57
2019-02-28 23:29:05 +01:00
Florian Müllner
9b25a227c6 style: Don't exempt ternary expressions from indent rule
It turns out we can comply with gjs' coding style and still align the
branches if line breaks are required, so do that to reduce diversion
from the canonical GNOME style.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/57
2019-02-28 23:28:55 +01:00
Florian Müllner
78580bc3a8 lint: Remove unused rules
We picked those up from Polari, which had those for

 - object arrays:
    let foo = [
        { bar: 42,
          quz: true },
        { bar: 23,
          quz: false }
    ];

 - "enums":

    let Options = {
        ONE:   0,
        TWO:   1,
        THREE: 2
    };

We don't have either of those, so drop the rules to minimise divergence
with gjs.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/57
2019-02-28 23:28:44 +01:00
Florian Müllner
b50074fd37 lint: Restrict deprecated Lang API
Now that we moved to ES standard replacements, let's make sure they
don't creep back in accidentally.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/57
2019-02-28 23:28:33 +01:00
Florian Müllner
47beeb1a8e ci: Allow gradual switch to new style
It doesn't make too much sense to declare parts of the existing style
"legacy", but then enforce it via CI. To allow for a gradual switch,
generate a report with all issues that eslint considers errors in both
configurations.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/50
2019-01-28 06:51:36 +01:00
Florian Müllner
85112394b3 lint: Allow marking variables/arguments as unused
Unused variables or arguments can indicate bugs, but they can also
help document the code, in particular in case of signal handlers
and destructuring.

Account for this by keeping the error, but set up patterns that allow
us to opt out of if for individual variables/arguments. For arguments
we pick a '_' prefix, while for variables we go with a suffix instead,
to not accidentally exempt private module-scope variables.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/50
2019-01-28 06:50:53 +01:00
Florian Müllner
190243ee89 lint: Add "legacy" configuration
Regarding coding style, gjs is moving in a direction that departs quite
significantly from the established style, in particular when indenting
multi-line array/object literals or method arguments:

Currently we are keeping those elements aligned, while the gjs rules now
expect them to use the regular 4-space indentation.

There are certainly good arguments that can be made for that move - it's
much less prone to leading to overly-long lines, and matches popluar JS
styles elsewhere. But switching coding style implies large diffs which
interfere with git-blame and friends, so in order to allow for a more
gradual change, add a separate set of "legacy" rules that match more
closely the style we would expect up to now.

It also disables the rules for quotes and template strings - the former
because we cannot match the current style to use double-quotes for
translatable strings and single-quotes otherwise, the latter because
template strings are still relatively new, so we haven't adopted them
yet.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/50
2019-01-28 06:50:45 +01:00
Florian Müllner
1141d996d9 lint: Don't require indent for GObject.registerClass()
That function will eventually be replaced with decorators, and we don't
want to re-indent all GObject classes when that happens, so allow class
declarations with no indent:

    GObject.registerClass(
    class Foo extends GObject.Object {
    });

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/50
2019-01-28 06:50:38 +01:00
Florian Müllner
f7cbd0d600 lint: Tweak indenting rule
I simply cannot deal with multi-line trinary expressions where the
two "branches" don't align, so add an exception for them.

And while the strict 4-line indent for objects is growing on me for
"regular" objects:

    let foo = new Foo({
        bar: 42,
        baz: 'bam'
    });

I do prefer the current style of compact braces and aligned properties
for object lists:

    let entries = [
        { name: 'foo',
          visible: true },
        { name: 'bar',
          halign: Gtk.Align.START }
    ];

So allow the latter style as well, at least for the time being.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/50
2019-01-28 06:50:31 +01:00
Florian Müllner
c704f0de55 lint: Allow single-line braces
When using arrow functions, we only omit the braces when we are using
the return value:

    this.get_children().filter(w => w.visible);

When braces are used, eslint by default enforces line breaks, but
there are cases where the expression is hardly less concise than
the above:

    this.get_children().forEach(w => { w.destroy(); });

So change the default to allow this.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/50
2019-01-28 06:50:19 +01:00
Florian Müllner
c8a1cd9c99 lint: Allow multiple spaces before key values
This is useful for imitating namespaced flags/enums:

```
const FooFlags = {
    NONE :   0,
    SMEAGLY: 1 << 0,
    SMOGLEY: 1 << 1,
    MUGGLY:  1 << 2
};
```

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/50
2019-01-28 06:50:10 +01:00
Florian Müllner
ff79588d3b lint: Enforce camelCase
All variables should be in camelCase, so configure the corresponding
rule to enforce this. Exempt properties for now, to accommodate the
existing practice of using C-style underscore names for construct
properties of introspected objects.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/50
2019-01-28 06:50:05 +01:00
Florian Müllner
8ae84703a4 lint: Enforce arrow notation
We replaced all Lang.bind() calls with arrow functions or the standardized
Function.prototype.bind(), at least for the former eslint has some options
to ensure that the old custom doesn't sneak back in.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/50
2019-01-28 06:49:59 +01:00
Florian Müllner
f18b281020 lint: Require spaces inside braces in object literals
Prohibiting spaces where the established GNOME style has required
them for a decade would be a harsh change for no good reason.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/50
2019-01-28 06:49:54 +01:00
Florian Müllner
75503b5f3c lint: Tweak the whitelist of globals
gjs doesn't include any gettext wrappers, and obviously can't know
about the shell's global object, so include those in the list of
globals.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/50
2019-01-28 06:49:42 +01:00
Florian Müllner
1d96f83362 lint: Import eslint rules from gjs
gjs started to run eslint during its CI a while ago, so there is an
existing rules set we can use as a starting point for our own setup.

As we will adapt those rules to our code base, we don't want those
changes to make it harder to synchronize the copy with future gjs
changes, so include the rules from a separate file rather than using
the configuration directly.

https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/50
2019-01-28 06:49:31 +01:00