Closed vladimirdoroch closed 3 months ago
:thinking: absolute paths will not work for resolving imports when the package is used?
Can you provide a minimal example?
I have a feeling you don't want to use no-unpublished-import
if you're not going to publish the package to a registry.
Code that would be deployed by Lambda Layer in file foo.ts
// mount point for Lambdas would be "/opt/foo"
export const bar = "";
Code that would be deployed as AWS Lambda Function and be attached to Lambda Layer above.
import { Handler, Context } from 'aws-lambda';
import { bar } from '/opt/foo'; // violates node/no-unpublished-import
{
"rules": {
"node/no-unpublished-import": ["error", {
"allowModules": [
"/opt/foo/bar/"
]
}]
}
Eslint returns the following exception:
Error: .eslintrc.json: Configuration for rule "node/no-unpublished-import" is invalid: Value "/opt/foo" should match pattern "^(?:@[a-zA-Z0-9-.]+/)?[a-zA-Z0-9-.]+$".
Turning off the rule in general is not a desired solution since we use it in a larger mono-repo with some lambdas in sub-directories. Would rather like to add an exception in the .eslintrc.json
as proposed but this does not work since the regEx pattern used does not work.
:thinking: I see, can you raise an issue in our maintained fork over at https://github.com/eslint-community/eslint-plugin-n please?
Will raise it as proposed. ty
I deploy AWS Lambda + AWS Lambda Layers.
Lambda Layers are mounted using an absolute path as
/opt/*
which is matched bynode/no-unplished-import
.I tried to set an exception for this in config
.eslintrc.json
as follows:This did not work out because the regEx used to match the strings in the "allowModules" block uses regEx Pattern
^(?:@[a-zA-Z0-9_\-.]+/)?[a-zA-Z0-9_\-.]+$
which basically does not match strings starting with a slash/
.This could be fixed by adding slash to the 2nd capture group
^(?:@[a-zA-Z0-9_\-.]+/)?[a-zA-Z0-9_\-/.]+$
This did not work so I disabled the rule by inline config.