summaryrefslogtreecommitdiffstats
path: root/pkgs/simple
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2025-07-18 14:58:22 +0200
committertv <tv@krebsco.de>2025-07-18 14:59:22 +0200
commit3a14327adc466beb2be96a8a21751f01b92d73e9 (patch)
tree0899290d769bfc55c8125527a98d09e67fb993f0 /pkgs/simple
parent9b2b52e7e5d163771a4f7b9a9331cda465bc1d8b (diff)
writePolkitRules: init
Diffstat (limited to 'pkgs/simple')
-rw-r--r--pkgs/simple/writePolkitRules.nix72
1 files changed, 72 insertions, 0 deletions
diff --git a/pkgs/simple/writePolkitRules.nix b/pkgs/simple/writePolkitRules.nix
new file mode 100644
index 0000000..af4cb49
--- /dev/null
+++ b/pkgs/simple/writePolkitRules.nix
@@ -0,0 +1,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"
+''