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

chore: adding depcheck step to post-commit hook #1523

Merged
merged 1 commit into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
78 changes: 78 additions & 0 deletions depcheck.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* README
* This file contains a subset of critical dependency validation rules for the transformer packages.
* There are certain dependencies we need to be careful of introducing as we refactor the transformers,
* including access to @aws-amplify/* namespaced packages (namely core, printer),
* but we also wish to limit imports to `fs`, and a few other particular places.
*/

// List of v2 transformer directories.
const GQL_V2_TRANSFORMER_PACKAGES = [
'amplify-graphql-auth-transformer',
'amplify-graphql-default-value-transformer',
'amplify-graphql-function-transformer',
'amplify-graphql-http-transformer',
'amplify-graphql-index-transformer',
'amplify-graphql-maps-to-transformer',
'amplify-graphql-model-transformer',
'amplify-graphql-predictions-transformer',
'amplify-graphql-relational-transformer',
'amplify-graphql-searchable-transformer',
'amplify-graphql-transformer-core',
'amplify-graphql-transformer-interfaces',
'graphql-transformer-common',
'graphql-mapping-template',
];

const TRANSFORMER_RESTRICTED_IMPORTS = [
'fs',
alharris-at marked this conversation as resolved.
Show resolved Hide resolved
'fs-extra',
'@aws-amplify/amplify-cli-core',
'@aws-amplify/amplify-prompts',
];

module.exports = {
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
env: {
es6: true,
node: true,
jest: true,
},
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
ecmaFeatures: {
arrowFunctions: true,
modules: true,
module: true,
},
project: ['tsconfig.base.json'],
},
plugins: ['@typescript-eslint'],
settings: {
'import/parsers': { '@typescript-eslint/parser': ['.ts', '.tsx'] },
'import/resolver': { typescript: {} },
},
ignorePatterns: [
'__tests__/**',
'*.test.ts',
'lib/**',
'node_modules',
'*/node_modules',
],
overrides: [
{
files: GQL_V2_TRANSFORMER_PACKAGES.map((packageName) => `packages/${packageName}/src/**`),
excludedFiles: [
'__tests__/**',
'*.test.ts',
],
rules: {
'no-restricted-imports': ['error', ...TRANSFORMER_RESTRICTED_IMPORTS.map((importName) => ({
name: importName,
message: `${importName} is not allowed in transformer v2 packages`,
}))],
},
},
],
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"update-cli-packages": "./scripts/update-cli-dependencies.sh && yarn",
"extract-api": "lerna run extract-api",
"verify-api-extract": "yarn extract-api && ./scripts/verify-extract-api.sh",
"verify-yarn-lock": "./scripts/verify-yarn-lock.sh"
"verify-yarn-lock": "./scripts/verify-yarn-lock.sh",
"lint-deps": "git diff --name-only --cached --diff-filter d | grep -E '\\.(js|jsx|ts|tsx)$' | xargs eslint --no-eslintrc --config depcheck.config.js"
},
"bugs": {
"url": "https://github.com/aws-amplify/amplify-category-api/issues"
Expand All @@ -62,7 +63,7 @@
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "yarn verify-commit && yarn lint-fix"
"pre-commit": "yarn verify-commit && yarn lint-fix && yarn lint-deps"
}
},
"author": "Amazon Web Services",
Expand Down