Skip to content

Commit 548bcd3

Browse files
feat: initial replacement of tslint with eslint
1 parent ae6184b commit 548bcd3

80 files changed

Lines changed: 17872 additions & 8230 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

eslint-plugins/no-dynamo.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Custom ESLint plugin for dynamo-easy specific rules
3+
*/
4+
5+
// eslint-disable-next-line import/no-internal-modules
6+
import { noDynamoNamedImport } from '../eslint-rules/no-dynamo-named-import'
7+
8+
const DEFAULT_RULE_NS = `dynamo-easy`
9+
10+
/** @type { import '@eslint/core'.Plugin } */
11+
const meta = { name: 'dynamo-easy/eslint-plugin-rules', haba: "gugu" }
12+
13+
/** @type Record<string, RuleDefinition> */
14+
const rules = {
15+
'no-dynamo-named-import': noDynamoNamedImport
16+
}
17+
18+
/** @type Record<string, ConfigObject> */
19+
const configs = {
20+
recommended: {
21+
name: 'recommended',
22+
plugins: {
23+
[DEFAULT_RULE_NS]: { meta, rules },
24+
},
25+
rules: {
26+
[`${DEFAULT_RULE_NS}/deny-parent-index-file-import`]: 'error',
27+
[`${DEFAULT_RULE_NS}/prefix-builtin-module-import`]: 'error',
28+
},
29+
},
30+
}
31+
32+
export default {
33+
meta,
34+
rules,
35+
configs,
36+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Custom ESLint rule: no-dynamo-named-import
3+
*
4+
* We prevent named imports from aws-sdk/clients/dynamodb, this is a design decision to be more obvious about where the
5+
* import is from, this is not common practice but because our code has a lot of code dependent on dynamoDB we do this
6+
* for easier reading and understanding
7+
*/
8+
9+
import { ESLintUtils } from '@typescript-eslint/utils'
10+
11+
export const noDynamoNamedImport = ESLintUtils.RuleCreator.withoutDocs(() => {
12+
return {
13+
create(context) {
14+
return {
15+
ImportDeclaration(node) {
16+
const moduleName = node.source.value
17+
18+
if (moduleName === 'aws-sdk/clients/dynamodb') {
19+
// Check if it's a named import
20+
if (node.specifiers && node.specifiers.length > 0) {
21+
const hasNamedImport = node.specifiers.some(
22+
(specifier) => specifier.type === 'ImportSpecifier'
23+
)
24+
25+
if (hasNamedImport) {
26+
context.report({
27+
node,
28+
messageId: 'namedImportNotAllowed',
29+
})
30+
}
31+
}
32+
}
33+
},
34+
}
35+
},
36+
}
37+
})
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Test for the no-dynamo-named-import ESLint rule
3+
*/
4+
5+
// eslint-disable-next-line import/no-internal-modules
6+
import {noDynamoNamedImport} from '../eslint-rules/no-dynamo-named-import.js'
7+
import {RuleTester} from 'eslint'
8+
9+
const ruleTester = new RuleTester({
10+
languageOptions: {
11+
parserOptions: {
12+
ecmaVersion: 2020,
13+
sourceType: 'module',
14+
},
15+
},
16+
})
17+
18+
ruleTester.run('no-dynamo-named-import', noDynamoNamedImport, {
19+
valid: [
20+
// Wildcard import is allowed
21+
{
22+
code: "import * as DynamoDB from 'aws-sdk/clients/dynamodb'",
23+
},
24+
// Imports from other modules are allowed
25+
{
26+
code: "import * as moment from 'moment'",
27+
},
28+
{
29+
code: "import { Config } from 'aws-sdk'",
30+
},
31+
],
32+
33+
invalid: [
34+
// Named imports from aws-sdk/clients/dynamodb are not allowed
35+
{
36+
code: "import { Key } from 'aws-sdk/clients/dynamodb'",
37+
errors: [
38+
{
39+
messageId: 'namedImportNotAllowed',
40+
},
41+
],
42+
},
43+
// Multiple named imports also not allowed
44+
{
45+
code: "import { Key, AttributeMap } from 'aws-sdk/clients/dynamodb'",
46+
errors: [
47+
{
48+
messageId: 'namedImportNotAllowed',
49+
},
50+
],
51+
},
52+
],
53+
})
54+
55+
// eslint-disable-next-line no-undef
56+
console.log('All tests passed!')
57+

eslint.config.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { defineScTsConfig } from '@shiftcode/eslint-config-recommended'
2+
// import noDynamoPlugin from './eslint-plugins/no-dynamo.js'
3+
4+
export default [
5+
...defineScTsConfig({
6+
languageOptions: { parserOptions: { project: ['./tsconfig.lint.json'] } },
7+
}),
8+
{
9+
files: ['**/*.{ts,mts,cts,js,mjs,cjs}'],
10+
rules: {
11+
'@typescript-eslint/naming-convention': 'off',
12+
'@typescript-eslint/no-unsafe-member-access': 'off',
13+
'@typescript-eslint/no-array-constructor': 'off',
14+
'@typescript-eslint/no-redundant-type-constituents': 'off',
15+
'@typescript-eslint/no-unsafe-return': 'off',
16+
'@typescript-eslint/no-unsafe-call': 'off',
17+
'@typescript-eslint/restrict-template-expressions': 'off',
18+
'@typescript-eslint/require-await': 'off',
19+
'simple-import-sort/exports': 'off',
20+
'simple-import-sort/imports': 'off',
21+
'@typescript-eslint/switch-exhaustiveness-check': 'off',
22+
'@typescript-eslint/member-ordering': 'off',
23+
}
24+
},
25+
{
26+
files: ['**/*.{ts,mts,cts,js,mjs,cjs}'],
27+
ignores: [
28+
'src/**/*', // ignore all files inside src/
29+
'!src/**/*.{spec,test}.ts', // un-ignore test files
30+
],
31+
rules: {
32+
'unused-imports/no-unused-vars': 'off'
33+
}
34+
}
35+
]

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
// eslint-disable-next-line no-undef
23
module.exports = {
34
preset: 'ts-jest',
45
testEnvironment: 'node',

0 commit comments

Comments
 (0)