udondan/iam-floyd

View on GitHub

Showing 97 of 99 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  public forUser(account: string, ...users: string[]) {
    users.forEach((user) =>
      this.addPrincipal(
        PrincipalType.aws,
        `arn:${this.defaultPartition}:iam::${account}:user/${user}`,
Severity: Major
Found in lib/shared/policy-statement/8-principals.ts and 1 other location - About 2 hrs to fix
lib/shared/policy-statement/8-principals.ts on lines 207..215

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 78.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  public forRole(account: string, ...roles: string[]) {
    roles.forEach((role) =>
      this.addPrincipal(
        PrincipalType.aws,
        `arn:${this.defaultPartition}:iam::${account}:role/${role}`,
Severity: Major
Found in lib/shared/policy-statement/8-principals.ts and 1 other location - About 2 hrs to fix
lib/shared/policy-statement/8-principals.ts on lines 191..199

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 78.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function constructor has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  constructor() {
    const project = new Project();
    project.manipulationSettings.set({
      quoteKind: QuoteKind.Single,
    });
Severity: Minor
Found in lib/generator/managed-policies.ts - About 1 hr to fix

    Function arnFixer has 48 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function arnFixer(
      service: string,
      resource: string,
      arn: string,
    ): string {
    Severity: Minor
    Found in lib/generator/fixes.ts - About 1 hr to fix

      Function conditionFixer has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function conditionFixer(
        service: string,
        condition: Condition,
      ): Condition {
        let fixed = 0;
      Severity: Minor
      Found in lib/generator/fixes.ts - About 1 hr to fix

        Function getContent has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function getContent(service: string): Promise<Module> {
          service = serviceFixer(service);
          process.stdout.write(`${service}: `.white);
          process.stdout.write('Fetching '.grey);
        
        
        Severity: Minor
        Found in lib/generator/index.ts - About 1 hr to fix

          Function fixPolicyStatement has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function fixPolicyStatement(project: Project) {
            // loop over files in ../lib/shared/policy-statement:
            for (const fileName of fs.readdirSync(`${lib}/shared/policy-statement`)) {
              if (fileName.endsWith('.ts') && !fileName.endsWith('.d.ts')) {
                const file = path.join(
          Severity: Minor
          Found in bin/mkcdk.ts - About 1 hr to fix

            Function addResourceTypes has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function addResourceTypes($: cheerio.Root, module: Module): Module {
              const resourceTypes: ResourceTypes = {};
              const tableResourceTypes = getTable($, 'Resource types');
              tableResourceTypes.find('tr').each((_, element) => {
                const tds = $(element).find('td');
            Severity: Minor
            Found in lib/generator/index.ts - About 1 hr to fix

              Function main has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              async function main() {
                const changelog = getChangelog();
              
                const toots: string[] = [];
                const split = changelog
              Severity: Minor
              Found in bin/toot.ts - About 1 hr to fix

                Function cdkApplyPrincipals has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  protected cdkApplyPrincipals() {
                    if (!this.cdkPrincipalsApplied) {
                      const mode = this.useNotPrincipal ? 'addNotPrincipals' : 'addPrincipals';
                      // @ts-ignore only available after swapping 1-base
                      this[mode](...this.cdkPrincipals);
                Severity: Minor
                Found in lib/shared/policy-statement/9-principals-CDK.ts - About 1 hr to fix

                  Function requestWithRetry has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function requestWithRetry(
                    url: string,
                    options: request.CoreOptions = {},
                    retries = 3,
                    backoff = 300,
                  Severity: Minor
                  Found in lib/generator/index.ts - About 1 hr to fix

                    Similar blocks of code found in 3 locations. Consider refactoring.
                    Open

                      public ifAwsRequestTag(
                        key: string,
                        value: string | string[],
                        operator?: Operator | string,
                      ) {
                    Severity: Major
                    Found in lib/shared/policy-statement/2-conditions.ts and 2 other locations - About 1 hr to fix
                    lib/shared/policy-statement/2-conditions.ts on lines 495..501
                    lib/shared/policy-statement/2-conditions.ts on lines 693..699

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 59.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 3 locations. Consider refactoring.
                    Open

                      public ifAwsResourceTag(
                        key: string,
                        value: string | string[],
                        operator?: Operator | string,
                      ) {
                    Severity: Major
                    Found in lib/shared/policy-statement/2-conditions.ts and 2 other locations - About 1 hr to fix
                    lib/shared/policy-statement/2-conditions.ts on lines 495..501
                    lib/shared/policy-statement/2-conditions.ts on lines 572..578

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 59.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Function getAwsServicesFromIamDocs has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function getAwsServicesFromIamDocs(): Promise<string[]> {
                      return new Promise((resolve, reject) => {
                        const url =
                          'https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_actions-resources-contextkeys.html';
                        requestWithRetry(url)
                    Severity: Minor
                    Found in lib/generator/index.ts - About 1 hr to fix

                      Similar blocks of code found in 3 locations. Consider refactoring.
                      Open

                        public ifAwsPrincipalTag(
                          key: string,
                          value: string | string[],
                          operator?: Operator | string,
                        ) {
                      Severity: Major
                      Found in lib/shared/policy-statement/2-conditions.ts and 2 other locations - About 1 hr to fix
                      lib/shared/policy-statement/2-conditions.ts on lines 572..578
                      lib/shared/policy-statement/2-conditions.ts on lines 693..699

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 59.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Function run has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      async function run() {
                        const args = process.argv.slice(2);
                      
                        const doFileSwap = !args.length || args.includes('--swap');
                        const doPackageJson = !args.length || args.includes('--package-json');
                      Severity: Minor
                      Found in bin/mkcdk.ts - About 1 hr to fix

                        Function add has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          public add(name: string, value: string, description: string) {
                            this.filesNames.forEach((fileName: string) => {
                              if (fileName === 'cdk-iam-floyd') {
                                this.files[fileName].collection
                                  .addMethod({
                        Severity: Minor
                        Found in lib/generator/managed-policies.ts - About 1 hr to fix

                          Function indexManagedPolicies has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          export async function indexManagedPolicies(): Promise<void> {
                            console.log('starting');
                            const managedPolicies = new ManagedPolicies();
                            const policyNames: string[] = [];
                            const policies = await getPolicies();
                          Severity: Minor
                          Found in lib/generator/managed-policies.ts - About 1 hr to fix

                            Function createIndex has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            export function createIndex() {
                              const filePath = './lib/generated/index.ts';
                              process.stdout.write('index: '.white);
                              process.stdout.write('Generating '.cyan);
                            
                            
                            Severity: Minor
                            Found in lib/generator/index.ts - About 1 hr to fix

                              Function conditionFixer has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                              Open

                              export function conditionFixer(
                                service: string,
                                condition: Condition,
                              ): Condition {
                                let fixed = 0;
                              Severity: Minor
                              Found in lib/generator/fixes.ts - About 1 hr to fix

                              Cognitive Complexity

                              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                              A method's cognitive complexity is based on a few simple rules:

                              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                              • Code is considered more complex for each "break in the linear flow of the code"
                              • Code is considered more complex when "flow breaking structures are nested"

                              Further reading

                              Severity
                              Category
                              Status
                              Source
                              Language