-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:SUI-Components/sui into typescrip…
…t-support
- Loading branch information
Showing
14 changed files
with
521 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/** | ||
* @fileoverview Ensure your code is not using CommonJS signatures like module.exports or moduel.exports.foo or require() or require.resolve() | ||
*/ | ||
'use strict' | ||
|
||
const dedent = require('string-dedent') | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Rule Definition | ||
// ------------------------------------------------------------------------------ | ||
|
||
/** @type {import('eslint').Rule.RuleModule} */ | ||
module.exports = { | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
description: 'Ensure that your code is using ems over commonjs modules', | ||
recommended: true, | ||
url: 'https://github.mpi-internal.com/scmspain/es-td-agreements/blob/master/30-Frontend/00-agreements' | ||
}, | ||
fixable: null, | ||
schema: [], | ||
messages: { | ||
forbiddenExports: dedent` | ||
Use module.* should be avoid. | ||
`, | ||
forbiddenRequires: dedent` | ||
Use require function should be avoid. | ||
`, | ||
forbiddenModuleRequire: dedent` | ||
Use module.require function should be avoid. | ||
`, | ||
forbiddenRequiresObjects: dedent` | ||
Use require.cache or require.extensions or require.main should be avoid. | ||
`, | ||
forbiddenRequireResolve: dedent` | ||
Use require.resolve function should be avoid. | ||
`, | ||
forbidden__filename: dedent` | ||
__filename should be avoid | ||
`, | ||
forbidden__dirname: dedent` | ||
__dirname should be avoid | ||
` | ||
} | ||
}, | ||
create: function (context) { | ||
return { | ||
CallExpression(node) { | ||
const isRequire = node.callee?.name === 'require' | ||
const isResolve = node.callee?.object?.name === 'require' && node.callee?.property?.name === 'resolve' | ||
const isModule = node.callee?.object?.name === 'module' && node.callee?.property?.name === 'require' | ||
|
||
const isRequireFormCreateRequire = node.parent?.parent?.body | ||
?.filter(node => node.type === 'ImportDeclaration') | ||
?.some( | ||
node => | ||
node.source?.value === 'module' && node.specifiers?.some(spec => spec.imported?.name === 'createRequire') | ||
) | ||
|
||
isRequire && | ||
!isRequireFormCreateRequire && | ||
context.report({ | ||
node, | ||
messageId: 'forbiddenRequires' | ||
}) | ||
|
||
isResolve && | ||
context.report({ | ||
node, | ||
messageId: 'forbiddenRequireResolve' | ||
}) | ||
|
||
isModule && | ||
context.report({ | ||
node, | ||
messageId: 'forbiddenModuleRequire' | ||
}) | ||
}, | ||
MemberExpression(node) { | ||
const isModule = | ||
node.object?.name === 'module' && | ||
['children', 'exports', 'filename', 'id', 'isPreloading', 'loaded', 'parent', 'path', 'paths'].some( | ||
property => node.property?.name === property | ||
) | ||
|
||
const isRequire = | ||
node.object?.name === 'require' && | ||
['cache', 'extensions', 'main'].some(property => node.property?.name === property) | ||
|
||
isModule && | ||
context.report({ | ||
node, | ||
messageId: 'forbiddenExports' | ||
}) | ||
|
||
isRequire && | ||
context.report({ | ||
node, | ||
messageId: 'forbiddenRequiresObjects' | ||
}) | ||
}, | ||
Identifier(node) { | ||
node.name === '__filename' && | ||
context.report({ | ||
node, | ||
messageId: 'forbidden__filename' | ||
}) | ||
|
||
node.name === '__dirname' && | ||
context.report({ | ||
node, | ||
messageId: 'forbidden__dirname' | ||
}) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* @fileoverview Ensure that at least all your UseCases are using @inlineError and @tracer decorator from sui | ||
*/ | ||
'use strict' | ||
|
||
const dedent = require('string-dedent') | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Rule Definition | ||
// ------------------------------------------------------------------------------ | ||
|
||
/** @type {import('eslint').Rule.RuleModule} */ | ||
module.exports = { | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
description: 'Ensure that at least all your UseCases are using @inlineError and @tracer decorator from sui', | ||
recommended: true, | ||
url: 'https://github.mpi-internal.com/scmspain/es-td-agreements/blob/master/30-Frontend/00-agreements' | ||
}, | ||
fixable: 'code', | ||
schema: [], | ||
messages: { | ||
missingInlineError: dedent` | ||
All our UseCases must have an @inlineError decorator. | ||
`, | ||
missingTracer: dedent` | ||
All our UseCases must have a @tracer() decorator. | ||
`, | ||
tracerMissCall: dedent` | ||
Your tracer decorator should be call always with the name of your class | ||
`, | ||
inlineErrorMissplace: dedent` | ||
the inlineError decorator should be always the first | ||
` | ||
} | ||
}, | ||
create: function (context) { | ||
return { | ||
MethodDefinition(node) { | ||
const className = node.parent?.parent?.id?.name | ||
const shouldExtendFromUseCase = node.parent?.parent?.superClass?.name === 'UseCase' | ||
const isExecute = node.key?.name === 'execute' && shouldExtendFromUseCase | ||
const hasInlineError = node.decorators?.some(node => node.expression?.name === 'inlineError') | ||
const tracerNode = node.decorators?.find(node => node.expression?.callee?.name === 'tracer') | ||
const isTracerCalledWithClassName = | ||
tracerNode?.expression?.callee?.name === 'tracer' && | ||
className + '#' + node.key?.name === tracerNode?.expression?.arguments[0]?.properties[0]?.value?.value && | ||
tracerNode?.expression?.arguments[0]?.properties[0]?.key?.name === 'metric' | ||
const isInlineErrorTheFirst = node.decorators?.at(-1)?.expression?.name === 'inlineError' | ||
|
||
isExecute && | ||
!hasInlineError && | ||
context.report({ | ||
node: node.key, | ||
messageId: 'missingInlineError' | ||
}) | ||
|
||
isExecute && | ||
hasInlineError && | ||
!isInlineErrorTheFirst && | ||
context.report({ | ||
node: node.key, | ||
messageId: 'inlineErrorMissplace' | ||
}) | ||
|
||
isExecute && | ||
!tracerNode && | ||
context.report({ | ||
node: node.key, | ||
messageId: 'missingTracer' | ||
}) | ||
|
||
tracerNode && | ||
!isTracerCalledWithClassName && | ||
context.report({ | ||
node: tracerNode, | ||
messageId: 'tracerMissCall', | ||
fix(fixer) { | ||
return fixer.replaceText(tracerNode.expression, `tracer({metric: '${className}#${node.key?.name}'})`) | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.