조건부 import에는 존재하지 않는 파일을 참조하지 마세요
조건부 import에는 존재하지 않는 파일을 참조하지 마세요
조건부 import는 플랫폼이나 환경에 따라 다른 파일을 가져올 때 쓰는 기능이에요. 그런데 조건식이 참이 되어 존재하지 않는 파일을 import하게 되면 런타임에 코드가 실패할 수 있어요. 이 린트 규칙이 그런 실수를 미리 막아 줘요.
본문
조건부 import에서 존재하지 않는 파일을 참조하지 마세요.
조건식이 평가되어 빠진 파일을 import해야 하는 상황이 되면 코드가 런타임에 실패할 수 있어요.
BAD:
import 'file_that_does_exist.dart'
if (condition) 'file_that_does_not_exist.dart';
GOOD:
import 'file_that_does_exist.dart'
if (condition) 'file_that_also_does_exist.dart';
활성화 방법
conditional_uri_does_not_exist 규칙을 활성화하려면 analysis_options.yaml 파일의 linter > rules 아래에 conditional_uri_does_not_exist를 추가하면 돼요.
linter:
rules:
- conditional_uri_does_not_exist
대신 YAML map 문법으로 린트 규칙을 설정한다면 linter > rules 아래에 conditional_uri_does_not_exist: true를 추가하면 돼요.
linter:
rules:
conditional_uri_does_not_exist: true