Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Adevinta Eslint rules #1722

Merged
merged 49 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
7e41dc7
feat(packages/eslint-plugin-sui): create few rules
carlosvillu Feb 6, 2024
c6ffa98
feat(packages/eslint-plugin-sui): make warning
carlosvillu Feb 7, 2024
0a2563e
feat(packages/sui-lint): Create reporter flag
carlosvillu Feb 7, 2024
e2cef86
feat(packages/eslint-plugin-sui): add empty rule
carlosvillu Feb 7, 2024
1ce2585
feat(packages/sui-lint): Add send method to the reporter
carlosvillu Feb 13, 2024
7d34092
feat(packages/sui-lint): Add send method to the reporter
carlosvillu Feb 14, 2024
ed4035f
feat(packages/sui-lint): Create RepositoryLinter and desactivate esli…
carlosvillu Feb 28, 2024
75a3684
refactor(packages/eslint-plugin-sui): eslint format
carlosvillu Feb 28, 2024
836098d
feat(packages/lint-repository-sui): Create first version of the Golde…
carlosvillu Feb 28, 2024
07293da
fix(packages/sui-lint): Fix JSReporter import and plugins version
carlosvillu Feb 28, 2024
36a3830
fix(packages/lint-repository-sui): Fix typo in rule
carlosvillu Feb 28, 2024
02cd409
fix(packages/sui-lint): Fix version
carlosvillu Feb 28, 2024
e0fd013
fix(packages/sui-lint): Fix lint
carlosvillu Feb 28, 2024
0836810
fix(packages/sui-lint): Fix lint
carlosvillu Feb 28, 2024
74751db
test(packages/eslint-plugin-sui): Add more tests
carlosvillu Mar 1, 2024
d057f60
test(packages/lint-repository-sui): Add firsts tests
carlosvillu Mar 1, 2024
3a8a6d5
test(packages/sui-lint): Add firsts tests to the RepositoryLinter
carlosvillu Mar 1, 2024
0727399
test(packages/sui-lint): Add more unit test for the RepositoryLinter …
carlosvillu Mar 4, 2024
1fa5d67
test(packages/eslint-plugin-sui): move to test/server folder
carlosvillu Mar 4, 2024
503b1bd
test(packages/lint-repository-sui): move tests to server
carlosvillu Mar 4, 2024
29e8166
test(packages/sui-lint): move to server folder
carlosvillu Mar 4, 2024
424b443
test(packages/eslint-plugin-sui): remove tests folder
carlosvillu Mar 4, 2024
69c7d64
test(packages/eslint-plugin-sui): fix import path
carlosvillu Mar 4, 2024
6ea3cd7
test(packages/lint-repository-sui): fix path import
carlosvillu Mar 4, 2024
b01ae7e
test(packages/sui-lint): fix import path
carlosvillu Mar 4, 2024
df3de9f
test(packages/eslint-plugin-sui): move folder
carlosvillu Mar 4, 2024
a704fc2
test(packages/lint-repository-sui): move folder
carlosvillu Mar 4, 2024
4b029c8
test(packages/sui-lint): move folder
carlosvillu Mar 4, 2024
176eeaf
test(Root): move folder
carlosvillu Mar 4, 2024
1c34ef2
Update packages/sui-lint/bin/sui-lint-js.js
carlosvillu Mar 5, 2024
ab16dc5
feat(packages/lint-repository-sui): add typescript lint repository rule
kikoruiz Mar 5, 2024
508fd84
feat(packages/sui-lint): add typescript lint repository rule
kikoruiz Mar 5, 2024
17c5f5e
refactor(packages/eslint-plugin-sui): avoid magic string
carlosvillu Mar 5, 2024
9d51b66
feat(packages/lint-repository-sui): Avoid magic strings
carlosvillu Mar 5, 2024
de098d6
refactor(packages/sui-lint): refactor copies
carlosvillu Mar 5, 2024
369b096
feat(packages/eslint-plugin-sui): Improve rules to be more resilient
carlosvillu Mar 8, 2024
164ddf2
feat(packages/lint-repository-sui): Use only the major version of Node
carlosvillu Mar 8, 2024
c42244c
feat(packages/sui-lint): Allow relative path in reporter flag and sel…
carlosvillu Mar 8, 2024
b944fb7
Merge branch 'master' of github.com:SUI-Components/sui into sui-lint-…
carlosvillu Mar 8, 2024
48b4ef6
feat(packages/sui-lint): Add flag to force lint all files
carlosvillu Mar 8, 2024
3865416
feat(packages/eslint-plugin-sui): fix more than one line in toJson
nucliweb Mar 8, 2024
e5c1cdd
Merge branch 'sui-lint-adv-rules' of github.com:SUI-Components/sui in…
nucliweb Mar 8, 2024
75d31c6
feat(packages/sui-lint): add new dependency
carlosvillu Mar 14, 2024
0324821
feat(packages/sui-lint): add new dependency
carlosvillu Mar 14, 2024
27c6e29
feat(packages/sui-lint): add new dependency
carlosvillu Mar 14, 2024
b66fd7d
feat(packages/sui-lint): disable sui checks
carlosvillu Mar 14, 2024
57e55cf
feat(packages/sui-lint): disable sui checks
carlosvillu Mar 14, 2024
958cfc6
feat(packages/sui-lint): fix lint
carlosvillu Mar 21, 2024
19dfdd6
chore(packages/eslint-plugin-sui): add npx
carlosvillu Mar 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@
"stylelint": {
"extends": "./node_modules/@s-ui/lint/stylelint.config.js"
}
}
}
58 changes: 58 additions & 0 deletions packages/eslint-plugin-sui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# eslint-plugin-sui

Set of sui lint rules

## Installation

You'll first need to install [ESLint](https://eslint.org/):

```sh
npm i eslint --save-dev
```

Next, install `eslint-plugin-sui`:

```sh
npm install eslint-plugin-sui --save-dev
```

## Usage

Add `sui` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:

```json
{
"plugins": [
"sui"
]
}
```


Then configure the rules you want to use under the rules section.

```json
{
"rules": {
"sui/rule-name": 2
}
}
```



## Configurations

<!-- begin auto-generated configs list -->
TODO: Run eslint-doc-generator to generate the configs list (or delete this section if no configs are offered).
<!-- end auto-generated configs list -->



## Rules

<!-- begin auto-generated rules list -->
TODO: Run eslint-doc-generator to generate the rules list.
<!-- end auto-generated rules list -->


35 changes: 35 additions & 0 deletions packages/eslint-plugin-sui/docs/rules/factory-pattern.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Ensure that our classes are using the convetion of has a static create method as factory. (`factory-pattern`)

Please describe the origin of the rule here.

## Rule Details

This rule aims to...

Examples of **incorrect** code for this rule:

```js

// fill me in

```

Examples of **correct** code for this rule:

```js

// fill me in

```

### Options

If there are any options, describe them here. Otherwise, delete this section.

## When Not To Use It

Give a short description of when it would be appropriate to turn off this rule.

## Further Reading

If there are other links that describe the issue this rule addresses, please include them here in a bulleted list.
38 changes: 38 additions & 0 deletions packages/eslint-plugin-sui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "eslint-plugin-sui",
"version": "1.0.0-beta.9",
"description": "Set of sui lint rules",
"keywords": [
"eslint",
"eslintplugin",
"eslint-plugin"
],
"author": "Sui",
"main": "./src/index.js",
"exports": "./src/index.js",
"scripts": {
"lint": "npx npm-run-all \"lint:*\"",
"lint:eslint-docs": "npx npm-run-all \"update:eslint-docs -- --check\"",
"lint:js": "npx eslint .",
"test": "npx sui-test server",
"update:eslint-docs": "npx eslint-doc-generator"
},
"dependencies": {
"requireindex": "1.2.0",
"string-dedent": "3.0.1"
},
"devDependencies": {
"@s-ui/test": "8",
"eslint": "8.19.0",
"eslint-doc-generator": "1.0.0",
"eslint-plugin-eslint-plugin": "5.0.0",
"eslint-plugin-node": "11.1.0"
},
"engines": {
"node": "^14.17.0 || ^16.0.0 || >= 18.0.0"
},
"peerDependencies": {
"eslint": ">=7"
},
"license": "ISC"
}
14 changes: 14 additions & 0 deletions packages/eslint-plugin-sui/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const FactoryPattern = require('./rules/factory-pattern.js')
const SerializeDeserialize = require('./rules/serialize-deserialize.js')

// ------------------------------------------------------------------------------
// Plugin Definition
// ------------------------------------------------------------------------------

// import all rules in lib/rules
module.exports = {
rules: {
'factory-pattern': FactoryPattern,
'serialize-deserialize': SerializeDeserialize
}
}
65 changes: 65 additions & 0 deletions packages/eslint-plugin-sui/src/rules/factory-pattern.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* @fileoverview Ensure that our classes are using the convetion of has a static create method as factory.
* @author factory pattern
*/
'use strict'

const dedent = require('string-dedent')

// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'warning',
docs: {
description: 'ensure to define at least one factory function',
recommended: true,
url: 'https://github.mpi-internal.com/scmspain/es-td-agreements/blob/master/30-Frontend/00-agreements'
},
fixable: null,
schema: [],
messages: {
notFoundFactoryFunction: dedent`
You have to define at least one static function that return an instance of your class.
Avoid to use the 'new' keyword directly in your code.
Use always a factory function
`
}
},
create: function (context) {
// variables should be defined here

// ----------------------------------------------------------------------
// Helpers
// ----------------------------------------------------------------------

// any helper functions should go here or else delete this section

// ----------------------------------------------------------------------
// Public
// ----------------------------------------------------------------------

return {
ClassDeclaration(node) {
const hasStaticFactoryMethod = Boolean(
node.body?.body?.find(methodDefinition => {
return (
methodDefinition.static &&
methodDefinition.value?.body?.body?.find?.(body => body.type === 'ReturnStatement')?.argument?.callee?.name === node?.id?.name // eslint-disable-line
)
})
)

if (!hasStaticFactoryMethod) {
context.report({
node: node?.id ?? node.superClass ?? node,
messageId: 'notFoundFactoryFunction'
})
}
}
}
}
}
46 changes: 46 additions & 0 deletions packages/eslint-plugin-sui/src/rules/forbidden-require.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @fileoverview Ensure that our coda doesnt have require (CJS) styles
* @author factory pattern
*/
'use strict'

const dedent = require('string-dedent')

// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'ensure to use only ESM (import) style',
recommended: true,
url: 'https://github.mpi-internal.com/scmspain/es-td-agreements/blob/master/30-Frontend/00-agreements'
},
fixable: null,
schema: [],
messages: {
badFileName: dedent``,
badClassName: dedent``
}
},
create: function (context) {
// variables should be defined here

// ----------------------------------------------------------------------
// Helpers
// ----------------------------------------------------------------------

// any helper functions should go here or else delete this section

// ----------------------------------------------------------------------
// Public
// ----------------------------------------------------------------------

return {
ClassDeclaration(node) {}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @fileoverview Ensure that our function are using always named parameters
* @author factory pattern
*/
'use strict'

const dedent = require('string-dedent')

// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'ensure to use named parameters',
recommended: true,
url: 'https://github.mpi-internal.com/scmspain/es-td-agreements/blob/master/30-Frontend/00-agreements'
},
fixable: null,
schema: [],
messages: {
badFileName: dedent``,
badClassName: dedent``
}
},
create: function (context) {
// variables should be defined here

// ----------------------------------------------------------------------
// Helpers
// ----------------------------------------------------------------------

// any helper functions should go here or else delete this section

// ----------------------------------------------------------------------
// Public
// ----------------------------------------------------------------------

return {
ClassDeclaration(node) {}
}
}
}
46 changes: 46 additions & 0 deletions packages/eslint-plugin-sui/src/rules/naming-convention.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @fileoverview Ensure that our classes are using the naming convention for UseCases, Services and Repositories
* @author factory pattern
*/
'use strict'

const dedent = require('string-dedent')

// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'ensure to use a proper naming convention',
recommended: true,
url: 'https://github.mpi-internal.com/scmspain/es-td-agreements/blob/master/30-Frontend/00-agreements'
},
fixable: null,
schema: [],
messages: {
badFileName: dedent``,
badClassName: dedent``
}
},
create: function (context) {
// variables should be defined here

// ----------------------------------------------------------------------
// Helpers
// ----------------------------------------------------------------------

// any helper functions should go here or else delete this section

// ----------------------------------------------------------------------
// Public
// ----------------------------------------------------------------------

return {
ClassDeclaration(node) {}
}
}
}
Loading
Loading