@appium/eslint-config-appium-ts 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +117 -0
  2. package/package.json +5 -4
  3. package/index.json +0 -22
package/index.js ADDED
@@ -0,0 +1,117 @@
1
+ /**
2
+ * `@appium/eslint-config-appium-ts` is a configuration for ESLint which extends
3
+ * `@appium/eslint-config-appium` and adds TypeScript support.
4
+ *
5
+ * It is **not** a _replacement for_ `@appium/eslint-config-appium`.
6
+ *
7
+ * It can be used _without any `.ts` sources_, as long as a `tsconfig.json` exists in the project
8
+ * root. In that case, it will run on `.js` files which are enabled for checking; this includes the
9
+ * `checkJs` setting and any `// @ts-check` directive in source files.
10
+ */
11
+
12
+ module.exports = {
13
+ $schema: 'http://json.schemastore.org/eslintrc',
14
+ parser: '@typescript-eslint/parser',
15
+ extends: ['@appium/eslint-config-appium', 'plugin:@typescript-eslint/recommended'],
16
+ rules: {
17
+ /**
18
+ * This rule is configured to warn if a `@ts-ignore` or `@ts-expect-error` directive is used
19
+ * without explanation.
20
+ * @remarks It's good practice to explain why things break!
21
+ */
22
+ '@typescript-eslint/ban-ts-comment': [
23
+ 'warn',
24
+ {
25
+ 'ts-expect-error': 'allow-with-description',
26
+ 'ts-ignore': 'allow-with-description',
27
+ },
28
+ ],
29
+ /**
30
+ * Empty functions are allowed.
31
+ * @remarks This is disabled because I need someone to explain to me why empty functions are bad. I suppose they _could_ be bugs, but so could literally any line of code.
32
+ */
33
+ '@typescript-eslint/no-empty-function': 'off',
34
+ /**
35
+ * Empty interfaces are allowed.
36
+ * @remarks This is because empty interfaces have a use case in declaration merging. Otherwise,
37
+ * an empty interface can be a type alias, e.g., `type Foo = Bar` where `Bar` is an interface.
38
+ */
39
+ '@typescript-eslint/no-empty-interface': 'off',
40
+ /**
41
+ * Explicit `any` types are allowed.
42
+ * @remarks Eventually this should be a warning, and finally an error, as we fully type the codebases.
43
+ */
44
+ '@typescript-eslint/no-explicit-any': 'off',
45
+ /**
46
+ * Warns if a non-null assertion (`!`) is used.
47
+ * @remarks Generally, a non-null assertion should be replaced by a proper type guard or
48
+ * type-safe function, if possible. For example, `Set.prototype.has(x)` is not type-safe, and
49
+ * does not imply that `Set.prototype.get(x)` is not `undefined` (I do not know why this is, but
50
+ * I'm sure there's a good reason for it). In this case, a non-null assertion is appropriate.
51
+ * Often a simple `typeof x === 'y'` conditional is sufficient to narrow the type and avoid the
52
+ * non-null assertion.
53
+ */
54
+ '@typescript-eslint/no-non-null-assertion': 'warn',
55
+ /**
56
+ * This disallows use of `require()`.
57
+ * @remarks We _do_ use `require()` fairly often to load files on-the-fly; however, these may
58
+ * want to be replaced with `import()` (I am not sure if there's a rule about that?). **If this check fails**, disable the rule for the particular line.
59
+ */
60
+ '@typescript-eslint/no-var-requires': 'error',
61
+ // 'no-unused-vars': 'off',
62
+ /**
63
+ * Allow native `Promise`s. **This overrides `@appium/eslint-config-appium`.**
64
+ * @remarks Originally, this was so that we could use [bluebird](https://npm.im/bluebird)
65
+ * everywhere, but this is not strictly necessary.
66
+ */
67
+ 'promise/no-native': 'off',
68
+ /**
69
+ * Allow `async` functions without `await`. **This overrides `@appium/eslint-config-appium`.**
70
+ * @remarks Originally, this was to be more clear about the return value of a function, but with
71
+ * the addition of types, this is no longer necessary. Further, both `return somePromise` and
72
+ * `return await somePromise` have their own use-cases.
73
+ */
74
+ 'require-await': 'off',
75
+
76
+ /**
77
+ * Disables the `brace-style` rule.
78
+ * @remarks Due to the way `prettier` sometimes formats extremely verbose types, sometimes it is necessary
79
+ * to indent in a way that is not allowed by the default `brace-style` rule.
80
+ */
81
+ 'brace-style': 'off',
82
+ },
83
+ /**
84
+ * This stuff enables `eslint-plugin-import` to resolve TS modules.
85
+ */
86
+ settings: {
87
+ 'import/parsers': {
88
+ '@typescript-eslint/parser': ['.ts', '.tsx'],
89
+ },
90
+ 'import/resolver': {
91
+ typescript: {
92
+ project: ['tsconfig.json', './packages/*/tsconfig.json'],
93
+ },
94
+ },
95
+ },
96
+ overrides: [
97
+ /**
98
+ * Overrides for tests.
99
+ */
100
+ {
101
+ files: ['**/test/**', '*.spec.js', '-specs.js', '*.spec.ts'],
102
+ rules: {
103
+ /**
104
+ * Both `@ts-expect-error` and `@ts-ignore` are allowed to be used with impunity in tests.
105
+ * @remarks We often test things which explicitly violate types.
106
+ */
107
+ '@typescript-eslint/ban-ts-comment': 'off',
108
+ /**
109
+ * Allow non-null assertions in tests; do not even warn.
110
+ * @remarks The idea is that the assertions themselves will be written in such a way that if
111
+ * the non-null assertion was invalid, the assertion would fail.
112
+ */
113
+ '@typescript-eslint/no-non-null-assertion': 'off',
114
+ },
115
+ },
116
+ ],
117
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appium/eslint-config-appium-ts",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Shared ESLint config for Appium projects (TypeScript version)",
5
5
  "keywords": [
6
6
  "eslint",
@@ -20,9 +20,9 @@
20
20
  },
21
21
  "license": "Apache-2.0",
22
22
  "author": "https://github.com/appium",
23
- "main": "index.json",
23
+ "main": "index.js",
24
24
  "files": [
25
- "index.json"
25
+ "index.js"
26
26
  ],
27
27
  "scripts": {
28
28
  "test:smoke": "exit 0"
@@ -33,6 +33,7 @@
33
33
  "@typescript-eslint/parser": "^5.5.0",
34
34
  "eslint": "^8.21.0",
35
35
  "eslint-config-prettier": "^8.5.0",
36
+ "eslint-import-resolver-typescript": "^3.5.0",
36
37
  "eslint-plugin-import": "^2.26.0",
37
38
  "eslint-plugin-mocha": "^10.1.0",
38
39
  "eslint-plugin-promise": "^6.0.0"
@@ -44,5 +45,5 @@
44
45
  "publishConfig": {
45
46
  "access": "public"
46
47
  },
47
- "gitHead": "0e164ba03de9579816011a2c27f9ab9f569d1e0e"
48
+ "gitHead": "d514ebdd7ebd27bb236509d0a3d580f0f18a34e5"
48
49
  }
package/index.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "$schema": "http://json.schemastore.org/eslintrc",
3
- "overrides": [
4
- {
5
- "files": ["*.ts", "*.tsx"],
6
- "parser": "@typescript-eslint/parser",
7
- "extends": ["@appium/eslint-config-appium", "plugin:@typescript-eslint/recommended"],
8
- "rules": {
9
- "@typescript-eslint/no-empty-function": 1,
10
- "@typescript-eslint/no-empty-interface": 0,
11
- "@typescript-eslint/no-explicit-any": 0,
12
- "@typescript-eslint/no-non-null-assertion": 0,
13
- "@typescript-eslint/no-var-requires": 1,
14
- "import/no-duplicates": 0,
15
- "import/no-unresolved": 0,
16
- "no-unused-vars": 0,
17
- "promise/no-native": 0,
18
- "require-await": 0
19
- }
20
- }
21
- ]
22
- }