-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into papi-slice-1
- Loading branch information
Showing
180 changed files
with
3,550 additions
and
1,999 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,3 @@ | ||
module.exports = { | ||
root: true, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:svelte/recommended', | ||
'prettier' | ||
], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['@typescript-eslint', 'eslint-plugin-local-rules', 'import'], | ||
parserOptions: { | ||
sourceType: 'module', | ||
ecmaVersion: 2020, | ||
extraFileExtensions: ['.svelte'], | ||
project: ['./tsconfig.eslint.json'] | ||
}, | ||
env: { | ||
browser: true, | ||
es2017: true, | ||
node: true | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['*.svelte'], | ||
parser: 'svelte-eslint-parser', | ||
parserOptions: { | ||
parser: '@typescript-eslint/parser' | ||
} | ||
}, | ||
{ | ||
files: ['scripts/**/*.mjs', 'scripts/**/*.ts'], | ||
rules: { | ||
'no-console': 'off' | ||
} | ||
}, | ||
{ | ||
files: ['*.svelte'], | ||
rules: { | ||
'import/order': [ | ||
'error', | ||
{ | ||
alphabetize: { order: 'asc' } | ||
} | ||
] | ||
} | ||
} | ||
], | ||
rules: { | ||
'@typescript-eslint/no-inferrable-types': 'error', | ||
'@typescript-eslint/no-unnecessary-type-assertion': 'error', | ||
'@typescript-eslint/no-unused-vars': [ | ||
'warn', | ||
{ | ||
argsIgnorePattern: '^_', | ||
varsIgnorePattern: '^_', | ||
caughtErrorsIgnorePattern: '^_' | ||
} | ||
], | ||
'@typescript-eslint/prefer-nullish-coalescing': 'error', | ||
'@typescript-eslint/prefer-reduce-type-parameter': 'error', | ||
'arrow-body-style': ['warn', 'as-needed'], | ||
curly: 'error', | ||
'local-rules/prefer-object-params': 'warn', | ||
'local-rules/no-svelte-store-in-api': 'error', | ||
'local-rules/use-option-type-wrapper': 'warn', | ||
'import/no-duplicates': ['error', { 'prefer-inline': true }], | ||
'no-console': ['error', { allow: ['error', 'warn'] }], | ||
'no-continue': 'warn', | ||
'no-delete-var': 'error', | ||
'no-else-return': ['warn', { allowElseIf: false }], | ||
'no-unused-vars': 'off', | ||
'prefer-template': 'error' | ||
}, | ||
globals: { | ||
NodeJS: true | ||
} | ||
}; | ||
extends: ["@dfinity/eslint-config-oisy-wallet/svelte"], | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,176 +1 @@ | ||
const { isNullish, nonNullish } = require('@dfinity/utils'); | ||
module.exports = { | ||
'no-svelte-store-in-api': { | ||
meta: { | ||
docs: { | ||
description: | ||
'Svelte stores should not be used in APIs since they are also utilized by workers.', | ||
category: 'Possible Errors', | ||
recommended: false | ||
}, | ||
schema: [] | ||
}, | ||
create(context) { | ||
return { | ||
ImportDeclaration(node) { | ||
const filePath = context.getFilename(); | ||
|
||
const { | ||
source: { value } | ||
} = node; | ||
|
||
if (filePath.includes('/api/') && value === 'svelte/store') { | ||
context.report({ | ||
node, | ||
message: "Importing 'svelte/store' is not allowed in API modules." | ||
}); | ||
} | ||
} | ||
}; | ||
} | ||
}, | ||
'use-option-type-wrapper': { | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
description: 'Enforce use of Option<T> instead of T | null | undefined', | ||
category: 'Best Practices', | ||
recommended: true | ||
}, | ||
fixable: 'code', | ||
schema: [] | ||
}, | ||
create: function (context) { | ||
const checkForOptionType = (node) => { | ||
if ( | ||
node.typeAnnotation.type === 'TSUnionType' && | ||
node.typeAnnotation.types.length === 3 && | ||
node.typeAnnotation.types.some((t) => t.type === 'TSNullKeyword') && | ||
node.typeAnnotation.types.some((t) => t.type === 'TSUndefinedKeyword') | ||
) { | ||
const type = node.typeAnnotation.types.find( | ||
(t) => t.type !== 'TSNullKeyword' && t.type !== 'TSUndefinedKeyword' | ||
); | ||
|
||
const typeText = | ||
type.type === 'TSTypeReference' && type.typeName && type.typeName.name | ||
? type.typeName.name | ||
: context.getSourceCode().getText(type); | ||
|
||
if (type) { | ||
try { | ||
context.report({ | ||
node, | ||
message: `Use Option<${typeText}> instead of ${typeText} | null | undefined.`, | ||
fix(fixer) { | ||
return fixer.replaceText(node.typeAnnotation, `Option<${typeText}>`); | ||
} | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
console.log(type); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
return { | ||
TSTypeAnnotation(node) { | ||
checkForOptionType(node); | ||
}, | ||
TSTypeAliasDeclaration(node) { | ||
checkForOptionType(node); | ||
} | ||
}; | ||
} | ||
}, | ||
'prefer-object-params': { | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
description: | ||
'Enforce passing parameters as an object when a function has more than one parameter', | ||
category: 'Best Practices', | ||
recommended: true | ||
}, | ||
schema: [] | ||
}, | ||
create(context) { | ||
const checkForMoreThanOneParameter = (node) => { | ||
const parent = node.parent; | ||
|
||
// Check if it is a callback for looping methods | ||
if ( | ||
nonNullish(parent) && | ||
parent.type === 'CallExpression' && | ||
parent.callee.type === 'MemberExpression' && | ||
['map', 'reduce', 'forEach', 'filter', 'sort', 'replace'].includes( | ||
parent.callee.property.name | ||
) | ||
) { | ||
return; | ||
} | ||
|
||
// Check if it is a callback for Array.from | ||
if ( | ||
nonNullish(parent) && | ||
parent.type === 'CallExpression' && | ||
parent.callee.type === 'MemberExpression' && | ||
parent.callee.object.name === 'Array' && | ||
parent.callee.property.name === 'from' | ||
) { | ||
return; | ||
} | ||
|
||
// Check if it is a callback in a Promise constructor | ||
if ( | ||
nonNullish(parent) && | ||
parent.type === 'NewExpression' && | ||
parent.callee.name === 'Promise' | ||
) { | ||
return; | ||
} | ||
|
||
// Check if it is a callback in JSON.stringify | ||
if ( | ||
nonNullish(parent) && | ||
parent.type === 'CallExpression' && | ||
parent.callee.type === 'MemberExpression' && | ||
parent.callee.object.name === 'JSON' && | ||
parent.callee.property.name === 'stringify' | ||
) { | ||
return; | ||
} | ||
|
||
// Check if it is inside a class constructor | ||
if ( | ||
nonNullish(parent) && | ||
parent.type === 'MethodDefinition' && | ||
parent.kind === 'constructor' | ||
) { | ||
return; | ||
} | ||
|
||
if (node.params.length > 1) { | ||
context.report({ | ||
node, | ||
message: | ||
'Functions with more than one parameter should accept an object and use destructuring.' | ||
}); | ||
} | ||
}; | ||
|
||
return { | ||
FunctionDeclaration(node) { | ||
checkForMoreThanOneParameter(node); | ||
}, | ||
FunctionExpression(node) { | ||
checkForMoreThanOneParameter(node); | ||
}, | ||
ArrowFunctionExpression(node) { | ||
checkForMoreThanOneParameter(node); | ||
} | ||
}; | ||
} | ||
} | ||
}; | ||
module.exports = require("@dfinity/eslint-config-oisy-wallet/eslint-local-rules"); |
Oops, something went wrong.