|
| 1 | +use std::fmt; |
| 2 | + |
1 | 3 | use derive_enum_from_into::EnumFrom; |
2 | | -use derive_more::Display; |
3 | 4 | use relative_path::RelativePath; |
4 | 5 |
|
5 | 6 | pub mod npv_100; |
@@ -36,7 +37,9 @@ pub mod npv_161; |
36 | 37 | pub mod npv_162; |
37 | 38 | pub mod npv_163; |
38 | 39 |
|
39 | | -#[derive(Clone, Display, EnumFrom)] |
| 40 | +const WIKI_BASE_URL: &str = "https://github.com/NixOS/nixpkgs-vet/wiki"; |
| 41 | + |
| 42 | +#[derive(Clone, EnumFrom)] |
40 | 43 | pub enum Problem { |
41 | 44 | /// NPV-100: attribute is not defined but it should be defined automatically |
42 | 45 | ByNameUndefinedAttribute(npv_100::ByNameUndefinedAttribute), |
@@ -133,6 +136,86 @@ pub enum Problem { |
133 | 136 | ), |
134 | 137 | } |
135 | 138 |
|
| 139 | +impl Problem { |
| 140 | + /// Returns the NPV error code for this problem (e.g. "NPV-100"). |
| 141 | + pub fn npv_code(&self) -> &'static str { |
| 142 | + match self { |
| 143 | + Self::ByNameUndefinedAttribute(..) => "NPV-100", |
| 144 | + Self::ByNameNonDerivation(..) => "NPV-101", |
| 145 | + Self::ByNameInternalCallPackageUsed(..) => "NPV-102", |
| 146 | + Self::ByNameCannotDetermineAttributeLocation(..) => "NPV-103", |
| 147 | + Self::ByNameOverrideOfNonSyntacticCallPackage(..) => "NPV-104", |
| 148 | + Self::ByNameOverrideOfNonTopLevelPackage(..) => "NPV-105", |
| 149 | + Self::ByNameOverrideContainsWrongCallPackagePath(..) => "NPV-106", |
| 150 | + Self::ByNameOverrideContainsEmptyArgument(..) => "NPV-107", |
| 151 | + Self::ByNameOverrideContainsEmptyPath(..) => "NPV-108", |
| 152 | + Self::ByNameShardIsNotDirectory(..) => "NPV-109", |
| 153 | + Self::ByNameShardIsInvalid(..) => "NPV-110", |
| 154 | + Self::ByNameShardIsCaseSensitiveDuplicate(..) => "NPV-111", |
| 155 | + Self::NixEvalError(..) => "NPV-120", |
| 156 | + Self::NixFileContainsPathInterpolation(..) => "NPV-121", |
| 157 | + Self::NixFileContainsSearchPath(..) => "NPV-122", |
| 158 | + Self::NixFileContainsPathOutsideDirectory(..) => "NPV-123", |
| 159 | + Self::NixFileContainsUnresolvablePath(..) => "NPV-124", |
| 160 | + Self::PackageContainsSymlinkPointingOutside(..) => "NPV-125", |
| 161 | + Self::PackageContainsUnresolvableSymlink(..) => "NPV-126", |
| 162 | + Self::NixFileContainsAbsolutePath(..) => "NPV-127", |
| 163 | + Self::NixFileContainsHomeRelativePath(..) => "NPV-128", |
| 164 | + Self::PackageDirectoryIsNotDirectory(..) => "NPV-140", |
| 165 | + Self::InvalidPackageDirectoryName(..) => "NPV-141", |
| 166 | + Self::PackageInWrongShard(..) => "NPV-142", |
| 167 | + Self::PackageNixMissing(..) => "NPV-143", |
| 168 | + Self::PackageNixIsNotFile(..) => "NPV-144", |
| 169 | + Self::TopLevelPackageMovedOutOfByName(..) => "NPV-160", |
| 170 | + Self::TopLevelPackageMovedOutOfByNameWithCustomArguments(..) => "NPV-161", |
| 171 | + Self::NewTopLevelPackageShouldBeByName(..) => "NPV-162", |
| 172 | + Self::NewTopLevelPackageShouldBeByNameWithCustomArgument(..) => "NPV-163", |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + /// Returns the wiki URL for this problem's documentation. |
| 177 | + pub fn wiki_url(&self) -> String { |
| 178 | + format!("{WIKI_BASE_URL}/{}", self.npv_code()) |
| 179 | + } |
| 180 | +} |
| 181 | + |
| 182 | +impl fmt::Display for Problem { |
| 183 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 184 | + match self { |
| 185 | + Self::ByNameUndefinedAttribute(inner) => inner.fmt(f), |
| 186 | + Self::ByNameNonDerivation(inner) => inner.fmt(f), |
| 187 | + Self::ByNameInternalCallPackageUsed(inner) => inner.fmt(f), |
| 188 | + Self::ByNameCannotDetermineAttributeLocation(inner) => inner.fmt(f), |
| 189 | + Self::ByNameOverrideOfNonSyntacticCallPackage(inner) => inner.fmt(f), |
| 190 | + Self::ByNameOverrideOfNonTopLevelPackage(inner) => inner.fmt(f), |
| 191 | + Self::ByNameOverrideContainsWrongCallPackagePath(inner) => inner.fmt(f), |
| 192 | + Self::ByNameOverrideContainsEmptyArgument(inner) => inner.fmt(f), |
| 193 | + Self::ByNameOverrideContainsEmptyPath(inner) => inner.fmt(f), |
| 194 | + Self::ByNameShardIsNotDirectory(inner) => inner.fmt(f), |
| 195 | + Self::ByNameShardIsInvalid(inner) => inner.fmt(f), |
| 196 | + Self::ByNameShardIsCaseSensitiveDuplicate(inner) => inner.fmt(f), |
| 197 | + Self::NixEvalError(inner) => inner.fmt(f), |
| 198 | + Self::NixFileContainsPathInterpolation(inner) => inner.fmt(f), |
| 199 | + Self::NixFileContainsSearchPath(inner) => inner.fmt(f), |
| 200 | + Self::NixFileContainsPathOutsideDirectory(inner) => inner.fmt(f), |
| 201 | + Self::NixFileContainsUnresolvablePath(inner) => inner.fmt(f), |
| 202 | + Self::PackageContainsSymlinkPointingOutside(inner) => inner.fmt(f), |
| 203 | + Self::PackageContainsUnresolvableSymlink(inner) => inner.fmt(f), |
| 204 | + Self::NixFileContainsAbsolutePath(inner) => inner.fmt(f), |
| 205 | + Self::NixFileContainsHomeRelativePath(inner) => inner.fmt(f), |
| 206 | + Self::PackageDirectoryIsNotDirectory(inner) => inner.fmt(f), |
| 207 | + Self::InvalidPackageDirectoryName(inner) => inner.fmt(f), |
| 208 | + Self::PackageInWrongShard(inner) => inner.fmt(f), |
| 209 | + Self::PackageNixMissing(inner) => inner.fmt(f), |
| 210 | + Self::PackageNixIsNotFile(inner) => inner.fmt(f), |
| 211 | + Self::TopLevelPackageMovedOutOfByName(inner) => inner.fmt(f), |
| 212 | + Self::TopLevelPackageMovedOutOfByNameWithCustomArguments(inner) => inner.fmt(f), |
| 213 | + Self::NewTopLevelPackageShouldBeByName(inner) => inner.fmt(f), |
| 214 | + Self::NewTopLevelPackageShouldBeByNameWithCustomArgument(inner) => inner.fmt(f), |
| 215 | + } |
| 216 | + } |
| 217 | +} |
| 218 | + |
136 | 219 | fn indent_definition(column: usize, definition: &str) -> String { |
137 | 220 | // The entire code should be indented 4 spaces |
138 | 221 | textwrap::indent( |
|
0 commit comments