.eslintrc.json (8261B)
1 { 2 "root": true, 3 "env": { 4 "browser": true, 5 "node": true 6 }, 7 "extends": ["./node_modules/gts"], 8 "overrides": [ 9 { 10 "files": ["**/*.ts"], 11 "parser": "@typescript-eslint/parser", 12 "parserOptions": { "project": "./tsconfig.json" }, 13 "extends": [ 14 "plugin:import/errors", 15 "plugin:import/warnings", 16 "plugin:import/typescript", 17 "plugin:n/recommended" 18 ], 19 "plugins": ["node", "ban", "import", "deprecation", "gpuweb-cts", "n"], 20 "rules": { 21 // Core rules 22 "linebreak-style": ["warn", "unix"], 23 "no-console": "warn", 24 "no-throw-literal": "warn", 25 "no-undef": "off", 26 "no-useless-rename": "warn", 27 "object-shorthand": "warn", 28 "prefer-promise-reject-errors": "warn", 29 "quotes": ["warn", "single", { "avoidEscape": true, "allowTemplateLiterals": true }], 30 31 // All test TODOs must be tracked inside file/test descriptions or READMEs. 32 // Comments relating to TODOs in descriptions can be marked with references like "[1]". 33 // TODOs not relating to test coverage can be marked MAINTENANCE_TODO or similar. 34 "no-warning-comments": [ 35 "warn", 36 { "terms": ["todo", "fixme", "xxx"], "location": "anywhere" } 37 ], 38 39 "no-restricted-syntax": [ 40 "warn", 41 { 42 "message": "createQuerySet must be immediately tracked using trackForCleanup (or use createQuerySetTracked).", 43 // This selector disallows any call to any method called "createQuerySet" 44 // that is not directly inside a call to some method called "trackForCleanup". 45 "selector": ":not(CallExpression[callee.property.name=\"trackForCleanup\"]) > CallExpression > MemberExpression > Identifier[name=\"createQuerySet\"]" 46 }, 47 { 48 "message": "createBuffer must be immediately tracked using trackForCleanup (or use createBufferTracked).", 49 // Similar to above. 50 "selector": ":not(CallExpression[callee.property.name=\"trackForCleanup\"]) > CallExpression > MemberExpression > Identifier[name=\"createBuffer\"]" 51 }, 52 { 53 "message": "createTexture must be immediately tracked using trackForCleanup (or use createTextureTracked).", 54 // Similar to above. 55 "selector": ":not(CallExpression[callee.property.name=\"trackForCleanup\"]) > CallExpression > MemberExpression > Identifier[name=\"createTexture\"]" 56 }, 57 { 58 "message": "Use requestDeviceTracked() instead of requestDevice().", 59 // We don't seem to need direct calls to requestDevice() at all so we can just disallow all of them. 60 "selector": "CallExpression > MemberExpression > Identifier[name=\"requestDevice\"]" 61 }, 62 { 63 "message": "Use hasFeature() instead of features.has().", 64 // features.has takes any string. We want only valid feature names. 65 "selector": "CallExpression[callee.property.name='has'][callee.object.name='features'],CallExpression[callee.property.name='has'][callee.object.property.name='features']" 66 } 67 ], 68 69 // Plugin: gpuweb-cts 70 "gpuweb-cts/string-trailing-space": "warn", 71 "gpuweb-cts/string-tabs": "warn", 72 73 // Plugin: @typescript-eslint 74 "@typescript-eslint/no-inferrable-types": "off", 75 "@typescript-eslint/consistent-type-assertions": "warn", 76 // Recommended lints 77 // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/README.md 78 "@typescript-eslint/adjacent-overload-signatures": "warn", 79 "@typescript-eslint/await-thenable": "warn", 80 "@typescript-eslint/ban-ts-comment": "warn", 81 "@typescript-eslint/no-empty-interface": "warn", 82 "@typescript-eslint/no-explicit-any": "warn", 83 "@typescript-eslint/no-extra-non-null-assertion": "warn", 84 "@typescript-eslint/no-floating-promises": "warn", 85 "@typescript-eslint/no-for-in-array": "warn", 86 "@typescript-eslint/no-misused-new": "warn", 87 "@typescript-eslint/no-namespace": "warn", 88 "@typescript-eslint/no-non-null-asserted-optional-chain": "warn", 89 "@typescript-eslint/no-this-alias": "warn", 90 "@typescript-eslint/no-unnecessary-type-assertion": "warn", 91 "@typescript-eslint/no-unnecessary-type-constraint": "warn", 92 "@typescript-eslint/no-unused-vars": [ 93 "warn", 94 // MAINTENANCE_TODO: Enable warnings for args 95 { "vars": "all", "args": "none", "varsIgnorePattern": "^_", "argsIgnorePattern": "^_" } 96 ], 97 "@typescript-eslint/prefer-as-const": "warn", 98 "@typescript-eslint/prefer-for-of": "warn", 99 "@typescript-eslint/prefer-namespace-keyword": "warn", 100 "@typescript-eslint/require-await": "warn", 101 "@typescript-eslint/restrict-plus-operands": "warn", 102 "@typescript-eslint/triple-slash-reference": "warn", 103 "@typescript-eslint/unbound-method": "warn", 104 // MAINTENANCE_TODO: Try to clean up and enable these recommended lints? 105 //"@typescript-eslint/no-unsafe-argument": "warn", 106 //"@typescript-eslint/no-unsafe-assignment": "warn", 107 //"@typescript-eslint/no-unsafe-call": "warn", 108 //"@typescript-eslint/no-unsafe-member-access": "warn", 109 //"@typescript-eslint/no-unsafe-return": "warn", 110 // Note: These recommended lints are probably not practical to enable. 111 //"@typescript-eslint/no-misused-promises": "warn", 112 //"@typescript-eslint/no-non-null-assertion": "warn", 113 //"@typescript-eslint/no-var-requires": "warn", 114 //"@typescript-eslint/restrict-template-expressions": "warn", 115 116 // Plugin: ban 117 "ban/ban": [ 118 "warn", 119 { 120 "name": "setTimeout", 121 "message": "WPT disallows setTimeout; use `common/util/timeout.js`." 122 } 123 ], 124 125 // Plugin: deprecation 126 //"deprecation/deprecation": "warn", 127 128 // Plugin: n (for Node) 129 "n/no-unsupported-features/es-syntax": "off", 130 "n/no-unsupported-features/node-builtins": "off", 131 "n/no-restricted-require": ["warn", ["*"]], 132 "n/no-restricted-import": [ 133 "warn", 134 [ 135 { 136 "name": ["*", "!./**/*.js", "!../**/*.js"], 137 "message": "All imports must end in .js and be relative for Web. If this a Node-only file, use an eslint-disable directive or subdirectory .eslintrc.json to disable this lint." 138 } 139 ] 140 ], 141 142 // Plugin: import 143 "import/order": [ 144 "warn", 145 { 146 "groups": ["builtin", "external", "internal", "parent", "sibling", "index"], 147 "newlines-between": "always", 148 "alphabetize": { "order": "asc", "caseInsensitive": false } 149 } 150 ], 151 "import/newline-after-import": ["warn", { "count": 1 }], 152 "import/no-duplicates": "warn", 153 "import/no-restricted-paths": [ 154 "warn", 155 { 156 "zones": [ 157 { 158 "target": "./src/webgpu", 159 "from": "./src/common", 160 "except": ["./framework", "./util"], 161 "message": "Non-framework common/ code imported from webgpu/ suite" 162 }, 163 { 164 "target": "./src/unittests", 165 "from": "./src/common", 166 "except": ["./framework", "./util", "./internal"], 167 "message": "Non-framework common/ code imported from unittests/ suite" 168 }, 169 { 170 "target": "./src/webgpu", 171 "from": "./src/unittests", 172 "message": "unittests/ suite imported from webgpu/ suite" 173 }, 174 { 175 "target": "./src/common", 176 "from": "./src", 177 "except": ["./common", "./external"], 178 "message": "Non common/ code imported from common/" 179 } 180 ] 181 } 182 ] 183 }, 184 "settings": { 185 "import/resolver": { 186 "./.eslint-resolver": {} 187 } 188 } 189 } 190 ] 191 }