@necrobox/eslint-plugin-no-only-tests 6.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Artem Frolkov and other contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # @necrobox/eslint-plugin-no-only-tests
2
+
3
+ [![npm](https://img.shields.io/npm/v/@necrobox/eslint-plugin-no-only-tests.svg)](https://www.npmjs.com/package/@necrobox/eslint-plugin-no-only-tests)
4
+
5
+ Disallow the use of `describe.only()` and `it.only()`.
6
+
7
+ [По-русски](./README.ru.md)
8
+
9
+ ## Installation
10
+
11
+ You'll first need to install [ESLint](http://eslint.org):
12
+
13
+ ```
14
+ $ npm i eslint --save-dev
15
+ ```
16
+
17
+ Next, install the plugin:
18
+
19
+ ```
20
+ $ npm install @necrobox/eslint-plugin-no-only-tests --save-dev
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ Add `@necrobox/eslint-plugin-no-only-tests` to the `plugins` section of your `.eslintrc` configuration file.
26
+ You can omit the `eslint-plugin-` prefix:
27
+
28
+ ```json
29
+ {
30
+ "plugins": [
31
+ "@necrobox/no-only-tests"
32
+ ]
33
+ }
34
+ ```
35
+
36
+
37
+ Then configure the rule under the `rules` section.
38
+
39
+ ```json
40
+ {
41
+ "rules": {
42
+ "@necrobox/no-only-tests/no-only": 2
43
+ }
44
+ }
45
+ ```
46
+
47
+ ## Rationale
48
+
49
+ When developers fix tests they may make the process easier by filtering tests using method `only` on `it` & `describe`.
50
+
51
+ However, such filters should not be in the repo when the project is running on CI.
52
+ So, we add this rule to our [ESLint config](https://github.com/necrobox/eslint-config) to check the existence of `only`
53
+ in the tests files. And we run linter using precommit-hook, which make it possible to prevent committing
54
+ when `only` does exist in the code.
package/README.ru.md ADDED
@@ -0,0 +1,53 @@
1
+ # @necrobox/eslint-plugin-no-only-tests
2
+
3
+ [![npm](https://img.shields.io/npm/v/@necrobox/eslint-plugin-no-only-tests.svg)](https://www.npmjs.com/package/@necrobox/eslint-plugin-no-only-tests)
4
+
5
+ **eslint-plugin-no-only-tests** — это плагин ESLint, который проверяет наличие в файлах `describe.only()` и `it.only()`, и в случае их обнаружения показывает предупреждение.
6
+
7
+ ## Установка
8
+
9
+ Для начала необходимо установить [ESLint](http://eslint.org):
10
+
11
+ ```
12
+ $ npm i eslint --save-dev
13
+ ```
14
+
15
+ Далее установить сам плагин:
16
+
17
+ ```
18
+ $ npm install @necrobox/eslint-plugin-no-only-tests --save-dev
19
+ ```
20
+
21
+ ## Использование
22
+
23
+ Необходимо добавить `@necrobox/eslint-plugin-no-only-tests` в раздел `plugins` конфигурационного файла `.eslintrc`.
24
+ Можно опустить префикс `eslint-plugin-`:
25
+
26
+ ```json
27
+ {
28
+ "plugins": [
29
+ "@necrobox/no-only-tests"
30
+ ]
31
+ }
32
+ ```
33
+
34
+ Далее настроить правило в разделе `rules`:
35
+
36
+
37
+ ```json
38
+ {
39
+ "rules": {
40
+ "@necrobox/no-only-tests/no-only": 2
41
+ }
42
+ }
43
+ ```
44
+
45
+ ## Мотивация
46
+
47
+ Когда разработчик отлаживает тесты локально, он может для упрощения процесса оставить включёнными только те из них,
48
+ которые сломаны. Удобнее всего это делать с помощью метода `only` в `it` и `describe`.
49
+
50
+ Однако, на CI нужно запускать все тесты.
51
+ Потому мы включаем в нашем [ESLint-конфиге](https://github.com/necrobox/eslint-config) этот плагин, и он проверяет,
52
+ не используется ли метод `only` в файлах с тестами. А сам линтер запускаем с помощью прекоммит-хука,
53
+ тем самым блокируя возможность коммита в случае наличия `only` в кодовой базе.
package/lib/index.js ADDED
@@ -0,0 +1,3 @@
1
+ module.exports.rules = {
2
+ 'no-only': require('./rules/no-only'),
3
+ };
@@ -0,0 +1,27 @@
1
+ module.exports = {
2
+ meta: {
3
+ docs: {
4
+ description: 'disallow the use of describe.only() and it.only()',
5
+ category: 'Best Practices',
6
+ recommended: true,
7
+ },
8
+ schema: [],
9
+ },
10
+
11
+ create(context) {
12
+ return {
13
+ CallExpression(node) {
14
+ const callee = node.callee;
15
+
16
+ if (callee.type === 'MemberExpression') {
17
+ if (['describe', 'it'].includes(callee.object.name) && callee.property.name === 'only') {
18
+ context.report({
19
+ node,
20
+ message: `Unexpected ${callee.object.name}.only`,
21
+ });
22
+ }
23
+ }
24
+ },
25
+ };
26
+ },
27
+ };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@necrobox/eslint-plugin-no-only-tests",
3
+ "version": "6.0.0",
4
+ "description": "Disallow the use of describe.only() and it.only()",
5
+ "keywords": [
6
+ "eslint",
7
+ "eslintplugin",
8
+ "eslint-plugin"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/necrobox/eslint-plugin-no-only-tests"
13
+ },
14
+ "files": [
15
+ "lib/"
16
+ ],
17
+ "author": "Artem Frolkov <art.frolkov@gmail.com> (https://github.com/artfrolkov)",
18
+ "license": "MIT",
19
+ "main": "lib/index.js",
20
+ "scripts": {
21
+ "lint": "eslint --cache --ext .js ./",
22
+ "test": "mocha tests --recursive"
23
+ },
24
+ "devDependencies": {
25
+ "@necrobox/eslint-config": "8.0.0",
26
+ "eslint": "7.32.0",
27
+ "mocha": "10.8.2"
28
+ }
29
+ }