No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

139 líneas
4.3 KiB

hace 4 años
  1. # Etherpad ESLint Shareable Config
  2. This package contains an [ESLint](https://eslint.org/) [shareable
  3. config](https://eslint.org/docs/developer-guide/shareable-configs) that is used
  4. by [Etherpad](https://etherpad.org/) and Etherpad plugins in the
  5. https://github.com/ether namespace. You are encouraged to use it for your own
  6. Etherpad plugins so that your code stays consistent with the Etherpad codebase.
  7. ## Available Configs
  8. * **`etherpad`**: Base config containing settings that are common to all files.
  9. * **`etherpad/node`**: Extends `etherpad` for code that runs in Node.js.
  10. * **`etherpad/browser`**: Extends `etherpad` for code that runs in the browser.
  11. * **`etherpad/tests`**: Extends `etherpad` for test code.
  12. * **`etherpad/tests/backend`**: Extends `etherpad/node` and `etherpad/tests` for
  13. backend test code.
  14. * **`etherpad/tests/frontend`**: Extends `etherpad/browser` and `etherpad/tests`
  15. for frontend test code.
  16. * **`etherpad/plugin`**: Applies the above configs to the appropriate files.
  17. Assumes the plugin follows the [typical file
  18. layout](https://etherpad.org/doc/latest/#index_folder_structure).
  19. ## Usage in an Etherpad Plugin
  20. 1. Install the shareable config and its dependencies:
  21. ```shell
  22. npm install --save-dev \
  23. eslint \
  24. eslint-plugin-eslint-comments \
  25. eslint-plugin-mocha \
  26. eslint-plugin-node \
  27. eslint-plugin-prefer-arrow \
  28. eslint-plugin-promise \
  29. eslint-plugin-you-dont-need-lodash-underscore \
  30. eslint-config-etherpad
  31. ```
  32. 2. Edit your `package.json` to use the shareable config:
  33. ```json
  34. "eslintConfig": {
  35. "root": true,
  36. "extends": "etherpad/plugin"
  37. },
  38. ```
  39. 3. If you `require('ep_etherpad-lite/*')` anywhere in your server-side code, add
  40. a peer dependency so that the `node` ESLint plugin won't complain about
  41. unavailable modules:
  42. ```json
  43. "peerDependencies": {
  44. "ep_etherpad-lite": ">=1.8.6"
  45. },
  46. ```
  47. Adding an entry to `peerDependencies` does not cause `npm install` to install
  48. that peer dependency; you must manually install it yourself:
  49. ```shell
  50. npm install --no-save ep_etherpad-lite@file:/path/to/etherpad-lite/src
  51. ```
  52. The above command creates a symlink at `node_modules/ep_etherpad-lite` that
  53. points to `/path/to/etherpad-lite/src`. Unfortunately, `npm` automatically
  54. deletes that symlink whenever you run `npm install` to install, add, or
  55. update a regular dependency, so remember to re-run the above command each
  56. time you run `npm install`.
  57. 4. *Optional but recommended:* Define a `lint` script so that you can run `npm
  58. run lint` to check the code:
  59. ```json
  60. "scripts": {
  61. "lint": "eslint ."
  62. },
  63. ```
  64. 5. *Optional but recommended:* Specify the minimum version of Node.js you
  65. support (ideally this would match [Etherpad's minimum required
  66. version](https://github.com/ether/etherpad-lite#requirements)) so that the
  67. `node` ESLint plugin can warn you when you use incompatible features:
  68. ```json
  69. "engines": {
  70. "node": ">=10.13.0"
  71. },
  72. ```
  73. 6. Apply automatic fixes. If you added the optional `lint` script to
  74. `package.json`, you can run:
  75. ```shell
  76. npm run lint -- --fix
  77. ```
  78. Or you can run:
  79. ```shell
  80. npx eslint --fix .
  81. ```
  82. ## Overrides
  83. If you need to tune the configs, you can specify
  84. [overrides](https://eslint.org/docs/user-guide/configuring#configuration-based-on-glob-patterns)
  85. in your `package.json`. For example:
  86. ```json
  87. "eslintConfig": {
  88. "root": true,
  89. "extends": "etherpad/plugin",
  90. "overrides": [
  91. {
  92. "files": ["static/js/shared/**/*"],
  93. "env": {
  94. "shared-node-browser": true
  95. },
  96. "extends": "etherpad/node"
  97. }
  98. ]
  99. },
  100. ```
  101. ## Copyright and License
  102. Copyright © 2020 Richard Hansen <rhansen@rhansen.org>
  103. Licensed under the [Apache License, Version 2.0](LICENSE) (the "License"); you
  104. may not use this file except in compliance with the License. You may obtain a
  105. copy of the License at
  106. http://www.apache.org/licenses/LICENSE-2.0
  107. Unless required by applicable law or agreed to in writing, software distributed
  108. under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  109. CONDITIONS OF ANY KIND, either express or implied. See the License for the
  110. specific language governing permissions and limitations under the License.