Recipe Name:
Use the Region enum
Description:
AWS recommends to use one of the constants in the Regions enum
Level:
warning
Language:
  • java
Tags:
  • framework specific
  • AWS
  • quality
Documentation

It is recommended to only use Region#of if the region is not defined in the enum software.amazon.awssdk.regions.Region. Using the enum will generate compile-time errors if the region is not available.

Before
Region newRegion = Region.of("us-east-1");
After
Region newRegion = Region.US_EAST_1;
Resources
Recipe
id: scw:aws:region-enum
version: 10
metadata:
  name: Use the Region enum
  shortDescription: 'AWS recommends to use one of the constants in the Regions enum '
  level: warning
  language: java
  enabled: true
  descriptionFile: descriptions/UsetheRegionenum.html
  tags: framework specific;AWS;quality
search:
  methodcall:
    args:
      1:
        type: java.lang.String
        value:
          containsUntrustedInput: false
    name: of
    declaration:
      type: software.amazon.awssdk.regions.Region
availableFixes:
- name: Use the Region enum
  actions:
  - rewrite:
      to: software.amazon.awssdk.regions.Region.{{#sed}}s/-/_/g,{{#upperCase}}{{{ arguments.0.value }}}{{/upperCase}}{{/sed}}