summaryrefslogtreecommitdiffstats
path: root/pkgs/simple/writePolkitRules.nix
blob: af4cb494dda00b7bca22fa4cebb23649b47fbcf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{ lib, pkgs, ... }:

name: text:

pkgs.runCommand name {
  nativeBuildInputs = [
    pkgs.eslint
  ];
  eslintConfig = /* js */ ''
    // ESLint flat config for Polkit rules (Duktape 2.7)
    export default [
      {
        files: [${builtins.toJSON name}],
        languageOptions: {
          ecmaVersion: 2016,
          sourceType: 'script',
          globals: {
            polkit: 'readonly',
          },
        },
        linterOptions: {
          reportUnusedDisableDirectives: true,
        },
        rules: {
          'no-unused-vars': 'warn',
          'no-undef': 'error',
          'no-console': 'off',
          'prefer-const': 'warn',
          'no-confusing-arrow': [
            'error',
            { allowParens: true },
          ],
          'no-constant-condition': 'warn',
          'no-restricted-syntax': [
            'error',
            {
              selector: 'AwaitExpression',
              message: 'Async/await is not supported in Polkit rules.',
            },
            {
              selector: 'ImportDeclaration',
              message: 'Modules are not supported.',
            },
            {
              selector: 'ExportNamedDeclaration',
              message: 'Modules are not supported.',
            },
            {
              selector: 'NewExpression[callee.name="Promise"]',
              message: 'Promises are not supported in Duktape.',
            },
            {
              selector: 'ClassDeclaration',
              message: 'Class syntax may behave inconsistently in Duktape.',
            },
          ]
        }
      }
    ];
  '';
  polkitRules = text;
  passAsFile = [
    "eslintConfig"
    "polkitRules"
  ];
} /* sh */ ''
  name=${lib.escapeShellArg name}
  ln -s "$polkitRulesPath" "$name"
  ln -s "$eslintConfigPath" eslint.config.js
  eslint "$name"
  cp -L "$name" "$out"
''