Skip to content

AEP-0143 Linter Rules

Standardized codes

Standardized codes

This rule attempts to enforce that standard codes for concepts like language, currency, etc. are consistently used rather than any alternatives, as mandated in AEP-143.

Details

This rule looks at any field with a name that looks close to a field with a common standardized code, but that is not exactly that. It complains if it finds one and suggests the correct field name.

It currently spots the following common substitutes:

  • content_type
  • country
  • currency
  • lang
  • language
  • mime
  • mimetype
  • tz
  • timezone

Examples

Incorrect code for this rule:

// Incorrect.
message Book {
string name = 1;
string lang = 2; // Should be `language_code`.
}

Correct code for this rule:

// Correct.
message Book {
string name = 1;
string language_code = 2;
}

Disabling

If you need to violate this rule, use a leading comment above the method. Remember to also include an aep.dev/not-precedent comment explaining why.

// (-- api-linter: core::0143::standardized-codes=disabled
// aep.dev/not-precedent: We need to do this because reasons. --)
message Book {
string name = 1;
string lang = 2;
}

If you need to violate this rule for an entire file, place the comment at the top of the file.

Standardized code strings

Standardized code strings

This rule attempts to enforce that standard codes for concepts like language, currency, etc. are strings, as mandated in AEP-143.

Details

This rule looks at any field with a name matching a standardized code, and complains if it has a type other than string.

It currently matches the following field names:

  • currency_code
  • country_code
  • language_code
  • mime_type
  • time_zone

Examples

Incorrect code for this rule:

// Incorrect.
// This enum should not exist.
enum LanguageCode {
LANGUAGE_CODE_UNSPECIFIED = 0;
EN_US = 1;
EN_GB = 2;
}
message Book {
string name = 1;
LanguageCode language_code = 2; // Should be `string`.
}

Correct code for this rule:

// Correct.
message Book {
string name = 1;
string language_code = 2;
}

Disabling

If you need to violate this rule, use a leading comment above the method. Remember to also include an aep.dev/not-precedent comment explaining why.

// (-- api-linter: core::0143::string-type=disabled
// aep.dev/not-precedent: We need to do this because reasons. --)
enum LanguageCode {
LANGUAGE_CODE_UNSPECIFIED = 0;
EN_US = 1;
EN_GB = 2;
}
message Book {
string name = 1;
LanguageCode language_code = 2;
}

If you need to violate this rule for an entire file, place the comment at the top of the file.