@1024pix/eslint-plugin 1.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/.github/workflows/publish.yml +32 -0
- package/.github/workflows/test.yml +16 -0
- package/.nvmrc +1 -0
- package/index.js +6 -0
- package/package.json +12 -0
- package/renovate.json +4 -0
- package/rules/no-sinon-stub-with-args-oneliner.js +42 -0
- package/rules/no-sinon-stub-with-args-oneliner.test.js +62 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: npm publish @1024pix/eslint-plugin
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
inputs:
|
|
6
|
+
version:
|
|
7
|
+
type: choice
|
|
8
|
+
required: true
|
|
9
|
+
options:
|
|
10
|
+
- patch
|
|
11
|
+
- minor
|
|
12
|
+
- major
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
publish-npm:
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
- uses: actions/setup-node@v3
|
|
20
|
+
with:
|
|
21
|
+
node-version-file: .nvmrc
|
|
22
|
+
cache: npm
|
|
23
|
+
registry-url: https://registry.npmjs.org/
|
|
24
|
+
- name: Setup git user
|
|
25
|
+
run: |
|
|
26
|
+
git config --global user.name "pix-service-auto-merge"
|
|
27
|
+
git config --global user.email "service+github.auto-merge@pix.fr"
|
|
28
|
+
- run: npm version ${{ inputs.version }}
|
|
29
|
+
- run: git push && git push --tags
|
|
30
|
+
- run: npm publish --access public
|
|
31
|
+
env:
|
|
32
|
+
NODE_AUTH_TOKEN: ${{secrets.NPM_PUBLISH_ACCESS_TOKEN}}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: npm run test
|
|
2
|
+
|
|
3
|
+
on: push
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
test:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
steps:
|
|
9
|
+
- uses: actions/checkout@v3
|
|
10
|
+
- uses: actions/setup-node@v3
|
|
11
|
+
with:
|
|
12
|
+
node-version: 18
|
|
13
|
+
registry-url: https://registry.npmjs.org/
|
|
14
|
+
|
|
15
|
+
- run: npm ci
|
|
16
|
+
- run: npm test
|
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
18.18.0
|
package/index.js
ADDED
package/package.json
ADDED
package/renovate.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function report(context, node) {
|
|
4
|
+
context.report({
|
|
5
|
+
node: node,
|
|
6
|
+
messageId: 'chainError',
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
meta: {
|
|
12
|
+
type: 'problem',
|
|
13
|
+
docs: {
|
|
14
|
+
description:
|
|
15
|
+
'Do not chain `sinon.stub()` with the `withArgs()` method in a one-liner',
|
|
16
|
+
},
|
|
17
|
+
messages: {
|
|
18
|
+
chainError:
|
|
19
|
+
'`sinon.stub()` should not be chained with the `withArgs` method.',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
create: function (context) {
|
|
23
|
+
return {
|
|
24
|
+
'VariableDeclarator > CallExpression > MemberExpression[property.name="returns"] > CallExpression > MemberExpression[property.name="withArgs"] > CallExpression > MemberExpression[property.name="stub"][object.name="sinon"]':
|
|
25
|
+
function (node) {
|
|
26
|
+
report(context, node);
|
|
27
|
+
},
|
|
28
|
+
'VariableDeclarator > CallExpression > MemberExpression[property.name="throws"] > CallExpression > MemberExpression[property.name="withArgs"] > CallExpression > MemberExpression[property.name="stub"][object.name="sinon"]':
|
|
29
|
+
function (node) {
|
|
30
|
+
report(context, node);
|
|
31
|
+
},
|
|
32
|
+
'VariableDeclarator > CallExpression > MemberExpression[property.name="resolves"] > CallExpression > MemberExpression[property.name="withArgs"] > CallExpression > MemberExpression[property.name="stub"][object.name="sinon"]':
|
|
33
|
+
function (node) {
|
|
34
|
+
report(context, node);
|
|
35
|
+
},
|
|
36
|
+
'VariableDeclarator > CallExpression > MemberExpression[property.name="rejects"] > CallExpression > MemberExpression[property.name="withArgs"] > CallExpression > MemberExpression[property.name="stub"][object.name="sinon"]':
|
|
37
|
+
function (node) {
|
|
38
|
+
report(context, node);
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const rule = require('./no-sinon-stub-with-args-oneliner.js'),
|
|
4
|
+
RuleTester = require('eslint').RuleTester;
|
|
5
|
+
|
|
6
|
+
const ruleTester = new RuleTester({
|
|
7
|
+
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
ruleTester.run('no-sinon-stub-with-args-oneliner', rule, {
|
|
11
|
+
valid: [
|
|
12
|
+
{
|
|
13
|
+
name: 'Only stub',
|
|
14
|
+
code: 'sinon.stub()',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: 'Sinon import then two liners',
|
|
18
|
+
code: "const stub = sinon.stub(); stub.withArgs('hello').returns('world')",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'Sinon import then object definition',
|
|
22
|
+
code: "import sinon from 'sinon'; const stub = { hello: sinon.stub().withArgs('hello').returns('world') }",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'Stub import then two liners',
|
|
26
|
+
code: "import { stub } from 'sinon'; const myStub = stub(); myStub.withArgs('hello').returns('world')",
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
// Not handled yet
|
|
30
|
+
{
|
|
31
|
+
name: 'Sinon import then onCall one liner',
|
|
32
|
+
code: "import sinon from 'sinon'; const myStub = sinon.stub().withArgs('hello').onCall(0).returns('world')",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'Stub import then one liner',
|
|
36
|
+
code: "import { stub } from 'sinon'; const myStub = stub().withArgs('hello').returns('world')",
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
|
|
40
|
+
invalid: [
|
|
41
|
+
{
|
|
42
|
+
name: 'One liner variable assignment with sinon import and returns',
|
|
43
|
+
code: `import sinon from 'sinon'; const stub = sinon.stub().withArgs('hello').returns('world')`,
|
|
44
|
+
errors: [{ messageId: 'chainError' }],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'One liner variable assignment with sinon import and throws',
|
|
48
|
+
code: `import sinon from 'sinon'; const stub = sinon.stub().withArgs('hello').throws('world')`,
|
|
49
|
+
errors: [{ messageId: 'chainError' }],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'One liner variable assignment with sinon import and resolves',
|
|
53
|
+
code: `import sinon from 'sinon'; const stub = sinon.stub().withArgs('hello').resolves('world')`,
|
|
54
|
+
errors: [{ messageId: 'chainError' }],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'One liner variable assignment with sinon import and rejects',
|
|
58
|
+
code: `import sinon from 'sinon'; const stub = sinon.stub().withArgs('hello').rejects('world')`,
|
|
59
|
+
errors: [{ messageId: 'chainError' }],
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
});
|