-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[feature request] Add top-level files
deno.json config to replace fmt.files
+ lint.files
+ test.files
#15300
Comments
Interesting I’ll look into the code later. |
Summaryto implement this feature, we need to handle cases like {
"files": { "exclude": ["npm/"] }
} The four casesthere's 4 possible combination for global
while case 1, 2 and 3 is unambigous, i'm unsure how to handle case 4. no global
|
#[derive(Clone, Debug, Default, Eq, PartialEq)] | |
pub struct FilesConfig { | |
pub include: Vec<PathBuf>, | |
pub exclude: Vec<PathBuf>, | |
} |
"files"
is represented as FilesConfig
.
pub fn to_files_config(&self) -> Result<Option<FilesConfig>, AnyError>
there could be a to_files_config
impl that returns optional filesconfig result.
"Local" Configs
Lines 688 to 696 in 2502a37
pub fn to_fmt_config(&self) -> Result<Option<FmtConfig>, AnyError> { | |
if let Some(config) = self.json.fmt.clone() { | |
let fmt_config: SerializedFmtConfig = serde_json::from_value(config) | |
.context("Failed to parse \"fmt\" configuration")?; | |
Ok(Some(fmt_config.into_resolved(&self.specifier)?)) | |
} else { | |
Ok(None) | |
} | |
} |
FmtConfig
, LintConfig
, TestConfig
is generated from ConfigFile
. via to_{}_config
impl. it returns Result<Option<{ConfigName}>, AnyError>
.
all three of them contains FilesConfig
as their field.
Resolving config type
use match
boilerplate
we could create a helper function that would do something like
implicit resolving:
Option<FilesConfig>
+ Option<FmtConfig>
-> FmtConfig
explicit resolving:
Option<FilesConfig>
+ Option<FmtConfig>
-> Option<FmtConfig>
the possible drawback is that we'd need to rewrite same code for each fmt
, lint
and test
, which is a bit bulky:
let filesConfigOption = Option<FilesConfig>;
let fmtConfigOption = Option<FmtConfig>;
match (filesConfigOption, fmtConfigOption) {
(Some(filesConfig), Some(fmtConfig)) => // ...
(None, Some(fmtConfig)) => // ...
(Some(filesConfig), None) => // ...
(None, None) => // ...
}
however it's least intrusive (no need to change struct/return type).
use generic local config
struct WithFilesConfig<T> {
data: T, // FmtConfig, LintConfig, TestConfig
files: FilesConfig,
}
impl WithFilesConfig<T> {
fn extend_files(self, files: FilesConfig) -> WithFilesConfig<T> {
WithFilesConfig {
files: self.files + files,
..self
}
}
}
it would remove the need to write duplicate code, but it could potentially break existing code and would need large refactoring.
in short, using match boilerplate would be preferred.
Others
since i'm new to rust, please point out if anything is incorrect. thanks in advance.
A problem about this, is that it creates some confusion around what this applies to (ex. it creates the question: do the cache, vendor, compile, doc subcommands grab from the "files" array?) and I wonder if this will cause issues in the future with future subcommands. It seems like the predominant usecase is to "exclude" so maybe this should be exclude only? |
what about |
some possible solutions: only allow exclude array{
"exclude": ["npm/"]
"fmt": {}
} use
|
#17778 doesn't seem to work with |
@selurvedu the excludes property added in #17778 was not for That said, the "exclude" property will be taken into account for #20813 once that is implemented. |
@dsherret thanks for clarifying. I guess I could use this for now: --- deno.json
+++ deno.json
@@ -1,7 +1,7 @@
{
"lock": true,
"tasks": {
- "check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx",
+ "check": "deno fmt --check && deno lint && find . -type d -name _ignored -prune -o -type f -iname '*.ts' -o -iname '*.tsx' -print | xargs deno check",
"start": "deno run -A --watch=routes/,components/,islands/ dev.ts",
"build": "deno run -A dev.ts build && deno cache main.ts",
"update": "deno run -A -r https://fresh.deno.dev/update .", This was supposed to include |
I have a JavaScript monorepo wherein some sub-projects do not comply to Deno. To fully ignore them, I have to add three
files.exclude
configs to my deno.json:I'd like a single top-level
files
config that had the same effect:This DRYs up the config at the expense of increasing the complexity. It feels more natural to me than updating three places to effectively fully ignore a directory.
References
The text was updated successfully, but these errors were encountered: