diff options
Diffstat (limited to 'pkgs/simple')
| -rw-r--r-- | pkgs/simple/writePolkitRules.nix | 72 |
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" +'' |
