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

Event types should be defined in metadata tags

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      The "XXXX" event type is missing in this metadata tag
    • Default Severity:
      Critical
    • Impact:
      High
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way
    • Covered Languages:
      Flex
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min

      Description

      According to the Flex documentation :

      In an ActionScript file, when you define component events or other aspects of a component that affect more than a single property, you add the metadata tag outside the class definition so that the metadata is bound to the entire class, as the following example shows:

      // Add the [Event] metadata tag outside of the class file. 
      [Event(name="enableChange", type="flash.events.Event")] 
      public class ModalText extends TextArea {
      
          ...
      
          // Define class properties/methods
          private var _enableTA:Boolean;
      
          // Add the [Inspectable] metadata tag before the individual property. 
          [Inspectable(defaultValue="false")] 
          public function set enableTA(val:Boolean):void {
              _enableTA = val;
              this.enabled = val;
          
              // Define event object, initialize it, then dispatch it. 
              var eventObj:Event = new Event("enableChange");
              dispatchEvent(eventObj);
          }
      }
      

      In this example, the "enableChange" event must be considered part of the API. Therefore, it should be strongly typed.

      Noncompliant Code Example

      [Event(name="enableChange")] 
      public class ModalText extends TextArea {...}
      

      Compliant Solution

      [Event(name="enableChange", type="flash.events.Event")] 
      public class ModalText extends TextArea {...}
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            freddy.mallet Freddy Mallet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: