Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-1128

Unnecessary imports should be removed

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Hide
      * Remove this unused import.
      * Remove this duplicate import.
      * Remove this unnecessary import.
      Show
      * Remove this unused import. * Remove this duplicate import. * Remove this unnecessary import.
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      PHP, Python, VB.Net, XML
    • Covered Languages:
      C#, CSS, Java, JavaScript
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      2min
    • Analysis Scope:
      Main Sources, Test Sources
    • Checkstyle:
      RedundantImport, UnusedImports
    • ESLint:
      no-duplicate-imports
    • PMD:
      DontImportJavaLang, DuplicateImports, ImportFromSamePackage, UnusedImports, UnusedImportsWithTypeResolution
    • Stylelint:
      no-duplicate-at-import-rules

      Description

      The imports part of a file should be handled by the Integrated Development Environment (IDE), not manually by the developer.
      Unused and useless imports should not occur if that is the case.
      Leaving them in reduces the code's readability, since their presence can be confusing.

      Noncompliant Code Example

      package my.company;
      
      import java.lang.String;        // Noncompliant; java.lang classes are always implicitly imported
      import my.company.SomeClass;    // Noncompliant; same-package files are always implicitly imported
      import java.io.File;            // Noncompliant; File is not used
      
      import my.company2.SomeType;
      import my.company2.SomeType;    // Noncompliant; 'SomeType' is already imported
      
      class ExampleClass {
      
        public String someString;
        public SomeType something;
      
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              fabrice.bellingard Fabrice Bellingard
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated: