### Compliant documentation comment example Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-field-type.md This example demonstrates the correct way to document structure keys by specifying their types or referencing existing definitions. ```bsl // Parameters: // Parameters - Structure: // * Key1 - Number - has type for key // * Key2 - See NonComplaint.Parameters Procedure Complaint(Parameters) Export // empty EndProcedure ``` -------------------------------- ### Compliant Common Module Example Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/common-module-missing-api.md This example shows a module procedure correctly marked with the Export keyword. ```bsl #Region Internal Procedure Test() Export //TODO EndProcedure #EndRegion ``` -------------------------------- ### Compliant &ChangeAndValidate Pragma Example Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/change-and-validate-instead-of-around.md This example shows the compliant usage of the &ChangeAndValidate pragma. It replaces &Around when ProceedWithCall is not used and allows for targeted code insertion or deletion. ```bsl &ChangeAndValidate("MyFunction") Function Ext1_MyFunction() #Delete Return 1; #EndDelete #Insert Return 2; #EndInsert EndFunction ``` -------------------------------- ### Compliant Export Function Example Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/export-procedure-missing-comment.md An example of an exported function correctly documented with parameters, return values, and usage examples. ```bsl #Region Public // Defines the availability of RoleNames roles to the current user, // as well as the availability of administrator rights. // // Parameters: // RoleNames - String - comma-separated names of roles whose availability is checked. // // Returns: // Boolean - True if at least one of the passed roles is available to the current user or the // current user has administrative rights. // // Example: // If RolesAvailable("UseReportMailingLists,SendMail") Then ... // Function RolesAvailable(RoleNames) Export // code here EndFunction #EndRegion ``` -------------------------------- ### Compliant Method Placement Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/module-structure-method-in-regions.md Example of a procedure correctly encapsulated within a region. ```bsl #Region Private Procedure Compliant() //... EndProcedure #EndRegion ``` -------------------------------- ### Noncompliant &Around Pragma Example Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/change-and-validate-instead-of-around.md This example demonstrates the noncompliant usage of the &Around pragma. Use &ChangeAndValidate instead when ProceedWithCall is not invoked. ```bsl &Around("MyFunction") Function Ext1_MyFunction() //Return 1; Return 2; EndFunction ``` -------------------------------- ### Noncompliant documentation comment example Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-field-type.md This example shows a procedure parameter documentation comment missing the required type definition for a structure key. ```bsl // Parameters: // Parameters - Structure: // * Key1 - has no type for key Procedure NonComplaint(Parameters) Export // empty EndProcedure ``` -------------------------------- ### Noncompliant Common Module Example Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/common-module-missing-api.md This example shows a module procedure without the Export keyword, which is noncompliant. ```bsl Procedure Test() //TODO EndProcedure ``` -------------------------------- ### Noncompliant Export Function Example Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/export-procedure-missing-comment.md An example of an exported function lacking the required documentation comments. ```bsl #Region Public Function RolesAvailable(RoleNames) Export // code here EndFunction #EndRegion ``` -------------------------------- ### Noncompliant usage of deprecated methods Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/use-non-recommended-method.md Examples of legacy methods that should be replaced with current platform-standard alternatives. ```bsl Message("Text"); Date = CurrentDate(); CommonForm1 = GetForm("CommonForm.CommonForm1"); ``` ```bsl Find(Catalog.Name, "Joy"); ``` -------------------------------- ### Noncompliant empty row usage in BSL Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/module-consecutive-blank-lines.md Example showing excessive empty lines between statements that violates the style guide. ```bsl Procedure Test() A1 = 1; A2 = 2; EndProcedure ``` -------------------------------- ### Compliant Module Structure with Flat Regions Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/module-structure-top-region.md This example demonstrates a compliant and recommended way to structure module code using flat regions. This improves code readability and maintainability by clearly defining sections. ```bsl #Region Public // Enter code here. #EndRegion #Region Internal // Enter code here. #EndRegion #Region Private // Enter code here. #EndRegion ``` -------------------------------- ### Compliant Documentation Comment Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-parameter-in-description-suggestion.md This example demonstrates the compliant method for documenting parameters in a multi-line comment. It correctly uses the 'Parameters:' keyword to separate parameter descriptions from the main description. ```bsl // Description // // Parameters: // Parameter1 - this parameter is the section of parameters Procedure Complaint(Parameters) Export // empty EndProcedure ``` -------------------------------- ### Compliant NotifyDescription usage Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/notify-description-to-server-procedure.md This example shows the correct implementation where the notification callback is defined as a client procedure, ensuring it is available for execution. ```bsl &AtClient Procedure Compliant() Notify = new NotifyDescription("CompliantNotify", ThisObject); EndProcedure &AtClient Procedure CompliantNotify() Export // Procedure is avalable at client! EndProcedure ``` -------------------------------- ### Compliant Documentation Comment Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-ref-link.md This example demonstrates a compliant procedure with correctly formed documentation comments. It includes valid links to external resources and internal methods, ensuring all references are resolvable. Use this pattern for proper documentation. ```bsl // See word - this "word" is not link in description // // Parameters: // Parameters - Here valid web-link See https://1c.ru // LinkToMethod - See NonComplaint() Procedure Complaint(Parameters, LinkToMethod) Export // empty EndProcedure ``` -------------------------------- ### Compliant Extension Method Naming Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/extension-method-prefix.md This example demonstrates the compliant naming convention for extension methods, where 'Ext1_Complient' includes the 'Ext1' prefix corresponding to the extension. ```bsl &After("Complient") Procedure Ext1_Complient() //TODO: Insert the handler content EndProcedure ``` -------------------------------- ### Compliant Pragma Case Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/bsl-canonical-pragma.md This example demonstrates the compliant use of a pragma with the correct canonical casing. Always adhere to the documented casing for pragmas. ```bsl &ChangeAndValidate("MyFunction") Function Ext1_MyFunction() EndFunction ``` -------------------------------- ### Compliant Procedure Documentation Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-type.md Example of a procedure documentation comment using the correct type definition. ```bsl // Parameters: // Parameters - Structure - correct type Procedure Complaint(Parameters) Export // empty EndProcedure ``` -------------------------------- ### Noncompliant FOR UPDATE Clause Example Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.ql/markdown/ql-using-for-update.md This example demonstrates the incorrect usage of the FOR UPDATE clause. It is not recommended in managed lock mode. ```bsl SELECT Doc.Ref FROM Document.RetailSale Doc WHERE Doc.Ref = &DocumentRef FOR UPDATE AccumulationRegister.MutualSettlementsByAgreement.Balance ``` -------------------------------- ### Non-compliant Documentation Comment Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-parameter-in-description-suggestion.md This example shows a non-compliant way to document parameters in a multi-line comment. The 'Parameters:' keyword is missing, and parameter descriptions are mixed with the general description. ```bsl // Description // // Parameters // Parameter1 - this parameter is part of description Procedure NonComplaint(Parameter1) Export // empty EndProcedure ``` -------------------------------- ### Noncompliant Parameter Documentation Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-parameter-section.md Examples of exported procedures with missing or incorrect parameter documentation sections. ```bsl // For export method all parameters should be in parameter section // // Parameters: // Parameters - Only first parameter here Procedure NonComplaint(Parameters, SecondParameter) Export // empty EndProcedure // Parameters: // Parameters - Method should not have parameter section Procedure NonComplaint2() Export // empty EndProcedure ``` -------------------------------- ### Noncompliant Temporary File Handling Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/missing-temporary-file-deletion.md This example demonstrates the failure to delete a temporary file after writing data to it. ```bsl IntermediateFileName= GetTempFileName("xml"); Data.Write(IntermediateFileName); // No file deletion ``` -------------------------------- ### Compliant Method Documentation in 1C:Enterprise Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-redundant-parameter-section.md This compliant example demonstrates correct documentation for a method without parameters. It omits the parameter section, adhering to best practices for code clarity. ```bsl // Method without parameters should not have such section Procedure Complaint() // empty EndProcedure ``` -------------------------------- ### Compliant Solution Without FOR UPDATE Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.ql/markdown/ql-using-for-update.md This example shows the compliant solution by omitting the FOR UPDATE clause, which is the recommended approach in managed lock mode. ```bsl SELECT Doc.Ref FROM Document.RetailSale Doc WHERE Doc.Ref = &DocumentRef ``` -------------------------------- ### Noncompliant client-accessible code Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/module-accessibility-at-client.md This example shows variables and procedures defined without access restrictions, making them accessible in client contexts. ```bsl Var moduleVar; Procedure BeforeDelete(Cancel) // Non-compliant EndProcedure Procedure Noncompiant() Export // empty EndProcedure moduleVar = Undefined; ``` -------------------------------- ### Compliant Export Procedure Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/redundant-export-method.md An example of an export procedure correctly encapsulated within a public region. ```bsl #Region Public Procedure Processing() Export EndProcedure #EndRegion ``` -------------------------------- ### Noncompliant Extension Method Naming Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/extension-method-prefix.md This example shows a noncompliant naming convention where the extension method 'Ext_NonComplient' does not have the required extension prefix. ```bsl &Before("NonComplient") Procedure Ext_NonComplient() //TODO: Insert the handler content EndProcedure ``` -------------------------------- ### Compliant Temporary File Deletion Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/missing-temporary-file-deletion.md This example shows the correct approach using a Try-Except block to ensure the temporary file is deleted after operations are complete. ```bsl IntermediateFileName= GetTempFileName("xml"); Data.Write(IntermediateFileName); // File operations ... // Deleting a temporary file Try DeleteFiles(IntermediateFileName); Exception WriteLogEvent(NStr("en = "My engine.Action'"), EventLogLevel.Error, , , DetailErrorDescription(ErrorInfo())); EndTry; ``` -------------------------------- ### Compliant empty row usage in BSL Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/module-consecutive-blank-lines.md Example showing the correct formatting with a single empty line between statements. ```bsl Procedure Test() A1 = 1; A2 = 2; EndProcedure ``` -------------------------------- ### Compliant Export Function Documentation Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-export-procedure-description-section.md Example of an exported function correctly including a description section that explains the function's purpose. ```bsl #Region Public // Defines the availability of RoleNames roles to the current user, // as well as the availability of administrator rights. // // Parameters: // RoleNames - String - comma-separated names of roles whose availability is checked. // // Returns: // Boolean - True if at least one of the passed roles is available to the current user or the // current user has administrative rights. // // Example: // If RolesAvailable("UseReportMailingLists,SendMail") Then ... // Function RolesAvailable(RoleNames) Export // code here EndFunction #EndRegion ``` -------------------------------- ### Compliant BSL documentation comment Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-description-ends-on-dot.md Example of a multi-line comment that correctly ends with a period. ```bsl // First line // second line. Procedure Complaint() Export // empty EndProcedure ``` -------------------------------- ### Compliant Event Handler Naming Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/module-attachable-event-handler-name.md Example of an event handler name that correctly uses the 'Attachable_' prefix. ```bsl // Parameters: // Item - FormField Procedure Correct(Item) Item.SetAction("OnChange", "Attachable_CorrectOnChange"); EndProcedure ``` -------------------------------- ### Noncompliant Array Type Definition in BSL Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-collection-item-type.md This example shows an incorrect way to define an array parameter in a documentation comment, omitting the item type. Use this pattern when you need to explicitly show a non-compliant example. ```bsl // Parameters: // Parameters - Array - here array without item type Procedure NonComplaint(Parameters) Export // empty EndProcedure ``` -------------------------------- ### Noncompliant NotifyDescription usage Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/notify-description-to-server-procedure.md This example demonstrates an invalid implementation where the notification callback is defined as a server procedure, which is inaccessible to the client. ```bsl &AtClient Procedure Noncompliant() Notify = new NotifyDescription("NoncompliantNotify", ThisObject); EndProcedure &AtServer Procedure NoncompliantNotify() Export // Procedure is not avalable at client! EndProcedure ``` -------------------------------- ### Self-assignment code patterns Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/self-assign.md Examples showing noncompliant self-assignment and the compliant approach. ```1C:Enterprise P1 = ""; P1 = P1; ``` ```1C:Enterprise P1 = ""; ``` -------------------------------- ### Compliant Form Event Handler Placement Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/module-structure-form-event-regions.md This example demonstrates a correctly placed form event handler (OnOpen) within the FormEventHandlers region. Ensure procedures used as event handlers are prefixed with '&AtClient', '&AtServer', or '&AtServerNoContext'. ```bsl #Region FormEventHandlers &AtClient Procedure OnOpen(Cancel) //TODO: Insert the handler content EndProcedure #EndRegion ``` -------------------------------- ### Noncompliant: Using Export Variables Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/object-module-export-variable.md This noncompliant example demonstrates the use of an export variable 'ConvertFiles' which can lead to hard-to-reproduce errors due to uncontrolled scope. Use this pattern with caution. ```bsl Var ConvertFiles Export; Procedure BeforeWrite(Cancel) If FileConversion Then ... EndProcedure // calling code FileObject.FileConversion = True; FileObject.Write(); ``` -------------------------------- ### Noncompliant Method Placement Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/module-structure-method-in-regions.md Example of a procedure defined outside of any region, which violates the module structure guidelines. ```bsl Procedure Noncompliant() //... EndProcedure ``` -------------------------------- ### Compliant Variable Declaration Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/module-structure-var-in-region.md Example of variable declarations organized within a region for improved module structure. ```bsl #Region Variables Var PresentationCurrency; Var SupportEmail; ... #EndRegion ``` -------------------------------- ### Noncompliant Variable Declaration Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/module-structure-var-in-region.md Example of variable declarations lacking organizational structure and documentation. ```bsl Var PresentationCurrency; Var SupportEmail; ``` -------------------------------- ### Compliant documentation comment structure Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-field-in-description-suggestion.md Example of a correctly formatted documentation comment using the required field definition syntax. ```bsl // Parameters: // Parameters - Structure - description: // * Key1 - Number - this field is extension of the structure Procedure Complaint(Parameters) Export // empty EndProcedure ``` -------------------------------- ### Noncompliant GoTo usage in 1C:Enterprise Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/use-goto-operator.md Example of code using the GoTo operator, which should be avoided to prevent ill-structured modules. ```bsl If ChartOfCalculationTypes = Object.ChartOfCalculationTypes Then GoTo ChartOfCalculationTypes; EndIf; ``` -------------------------------- ### Noncompliant Procedure Documentation Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-type.md Example of a procedure documentation comment using an incorrect type definition. ```bsl // Parameters: // Parameters - Structure1 - incorrect type Procedure NonComplaint(Parameters) Export // empty EndProcedure ``` -------------------------------- ### Noncompliant Event Handler Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/data-exchange-load.md This example shows an event handler without the necessary DataExchange.Load check. Use this pattern when the check is not required. ```bsl Procedure BeforeWrite(Cancel) // handler code // ... EndProcedure ``` -------------------------------- ### Noncompliant Export Procedure Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/redundant-export-method.md An example of an export procedure that is not wrapped in a region, which may be flagged as unused. ```bsl Procedure Processing() Export EndProcedure ``` -------------------------------- ### Noncompliant Form Event Handler Placement Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/module-structure-form-event-regions.md This example shows a procedure within the FormEventHandlers region that is not a recognized form event handler. Use specific event handler procedures like OnOpen or OnCreateAtServer. ```bsl #Region FormEventHandlers Procedure WrongMethod() //TODO: Insert the handler content EndProcedure #EndRegion ``` -------------------------------- ### Compliant Deprecated Procedure Placement Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/deprecated-procedure-outside-deprecated-region.md Example showing the correct placement of a deprecated procedure within a nested Deprecated region inside the Public region. ```bsl #Region Public #Region Deprecated // Deprecated. Instead, use SupportedProcedure Procedure DeprecatedProcedure() Export DeprecatedProcedure() EndProcedure #EndRegion #EndRegion ``` -------------------------------- ### Compliant Extension Variable Naming Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/extension-variable-prefix.md Extension variables must have a prefix corresponding to the extension's prefix. This example shows a compliant naming. ```bsl Var Ext1_Perem Export; ``` -------------------------------- ### Compliant Documentation Comment Field Use Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-complex-type-with-link.md This compliant example demonstrates the correct way to declare a complex type in a documentation comment field by directly referencing it. ```bsl // Parameters: // Parameters - See NewStructureObject Procedure Complaint(Parameters) Export // empty EndProcedure // Returns: // Parameters - Structure: // * Key1 - Number - has type for key Function NewStructureObject() // empty EndFunction ``` -------------------------------- ### Noncompliant Event Handler Naming Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/module-attachable-event-handler-name.md Example of an event handler name that fails to follow the required naming convention. ```bsl // Parameters: // Item - FormField Procedure Incorrect(Item) Item.SetAction("OnChange", "IncorrectOnChange"); EndProcedure ``` -------------------------------- ### Noncompliant Export Function Documentation Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-export-procedure-description-section.md Example of an exported function missing the required description section in its documentation comment. ```bsl #Region Public // Parameters: // RoleNames - String - comma-separated names of roles whose availability is checked. // // Returns: // Boolean - True if at least one of the passed roles is available to the current user or the // current user has administrative rights. // // Example: // If RolesAvailable("UseReportMailingLists,SendMail") Then ... // Function RolesAvailable(RoleNames) Export // code here EndFunction #EndRegion ``` -------------------------------- ### Compliant Event Handler with DataExchange.Load Check Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/data-exchange-load.md This example demonstrates a compliant event handler that includes a check for DataExchange.Load. This pattern should be used to prevent unintended operations during data exchange loads. ```bsl Procedure BeforeWrite(Cancel) If DataExchange.Load Then Return; EndIf; // handler code // ... EndProcedure ``` -------------------------------- ### Noncompliant Module Structure with Nested Regions Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/module-structure-top-region.md This example shows a noncompliant way of structuring module code with nested regions, which can lead to confusion. Ensure regions are properly closed. ```bsl #Region Public // Enter code here. #EndRegion #Region Internal // Enter code here. #Region Private // Enter code here. #EndRegion #EndRegion ``` -------------------------------- ### Non-compliant Documentation Comment Field Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-field-type-strict.md This example shows a procedure where a parameter's documentation comment field 'Key1' lacks a type definition, violating strict type checking rules. ```bsl // Parameters: // Parameters - Structure: // * Key1 - has no type for key Procedure NonComplaint(Parameters) Export // empty EndProcedure ``` -------------------------------- ### Noncompliant Documentation Comment Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-ref-link.md This example shows a noncompliant procedure where a parameter reference in the comment does not resolve to an existing object. Use this pattern when you want to highlight incorrect referencing. ```bsl // Parameters: // Parameters - See Complaint.UnknownParameter Procedure NonComplaint(Parameters) Export // empty EndProcedure ``` -------------------------------- ### Typed value added to untyped collection examples Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/typed-value-adding-to-untyped-collection.md Compares noncompliant and compliant usage of the Add() method in BSL when strict typing is enabled. ```bsl // @strict-types Result = New Array(); Result.Add(42); ``` ```bsl // @strict-types Result = New Array(); // Array of Number Result.Add(42); ``` -------------------------------- ### Compliant Documentation Comment Field with Type Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-field-type-strict.md This example demonstrates a procedure where the parameter's documentation comment fields 'Key1' and 'Key2' have explicit type definitions ('Number' and 'See NonComplaint.Parameters' respectively), adhering to strict type checking. ```bsl // Parameters: // Parameters - Structure: // * Key1 - Number - has type for key // * Key2 - See NonComplaint.Parameters Procedure Complaint(Parameters) Export // empty EndProcedure ``` -------------------------------- ### Invalid Variable Names in 1C:Enterprise Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/bsl-variable-name-invalid.md Examples of variable names that do not follow the established naming conventions. Avoid names starting with underscores or using abbreviations that obscure meaning. ```bsl arrOfAtrribute, _SetTypeDoc, nS ``` -------------------------------- ### Structure initialization using Insert method Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/structure-consructor-too-many-keys.md Uses the Insert method to populate the Structure, which is the recommended compliant approach. ```bsl Parameters = new Structure(); Parameters.Insert("Key1"); Parameters.Insert("Key2"); Parameters.Insert("Key3"); Parameters.Insert("Key3"); ``` -------------------------------- ### Noncompliant Pragma Case Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/bsl-canonical-pragma.md This example shows a noncompliant pragma where the casing is incorrect. Ensure pragmas match the canonical casing. ```bsl &CHANGEandvalidate("MyFunction") Function Ext1_MyFunction() EndFunction ``` -------------------------------- ### Compliant Documentation Comment with Hyphen-Minus Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-use-minus.md This example demonstrates the correct usage of the hyphen-minus symbol (-) in a documentation comment. This ensures proper parsing of the documentation comment model. ```bsl // Parameters: // Parameters - Structure - both are minus: // * Key1 - Number - used correct minus Procedure Complaint(Parameters) Export // empty EndProcedure ``` -------------------------------- ### Execute Using Standard Subsystems Library Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/server-execution-safe-mode.md Use Common.ExecuteInSafeMode() from the Standard Subsystems Library for safe execution. ```bsl Common.ExecuteInSafeMode() ``` -------------------------------- ### DataLock Lock() usage examples Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/lock-out-of-try.md Demonstrates the noncompliant pattern where Lock() is called outside a try block and the compliant pattern using a transaction with exception handling. ```bsl DataLock = new DataLock; DataLockItem = DataLock.Add("Document.Test"); DataLockItem.Mode = DataLockMode.Exclusive; DataLock.Lock(); ``` ```bsl BeginTransaction(); Try DataLock = new DataLock; DataLockItem = DataLock.Add("Document.Test"); DataLockItem.Mode = DataLockMode.Exclusive; DataLock.Lock(); CommitTransaction(); Except RollbackTransaction(); Raise; EndTry; ``` -------------------------------- ### Compliant LIKE Usage in 1C Query Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.ql/markdown/ql-like-expression-with-field.md Use constant string literals or query parameters as the right operand for LIKE and ESCAPE operations. This example demonstrates correct usage with literals and escape characters. ```bsl SELECT StocksBalanceAndTurnovers.Warehouse FROM AccumulationRegister.Stocks.BalanceAndTurnovers AS StocksBalanceAndTurnovers WHERE StocksBalanceAndTurnovers.Warehouse LIKE "123%!%" ESCAPE "!" ``` -------------------------------- ### Noncompliant Deprecated Procedure Placement Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/deprecated-procedure-outside-deprecated-region.md Example showing a deprecated procedure placed directly in the Public region without a dedicated Deprecated region. ```bsl #Region Public // Deprecated. Instead, use SupportedProcedure Procedure DeprecatedProcedure() Export DeprecatedProcedure() EndProcedure #EndRegion ``` -------------------------------- ### Declare Module Variable With Hidden Initialization Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/variable-value-type.md Noncompliant example: Declaring a module variable and initializing it within a method, which can lead to issues if not handled carefully, especially with data exchange. ```bsl // @strict-types Var ObjectParameters; Procedure BeforeWrite(Cancel) If DataExchange.Load Then Return; EndIf; ObjectParameters = NewObjectParameters(); If ValueIsFilled(ObjectParameters.Param1) Then // code here EndIf; EndProcedure // Returns: // Structure: // * Param1 - String - Function NewObjectParameters() Params = New Structure(); Params.Insert("Param1", "String value"); return Params; EndFunction ``` -------------------------------- ### Compliant Array Type Definition in BSL Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-collection-item-type.md This example demonstrates the correct way to define an array parameter in a documentation comment by specifying the item type (e.g., 'Array of Number'). This improves code clarity and maintainability. ```bsl // Parameters: // Parameters - Array of Number - has type of collection item Procedure Complaint(Parameters) Export // empty EndProcedure ``` -------------------------------- ### Initialization Section Structure Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/module-structure-init-code-in-region.md Use #Region and #EndRegion directives to encapsulate initialization logic. ```bsl SupportEmail = "v8@1c.ru"; Ctor(); ... ``` ```bsl #Region Initialize SupportEmail = "v8@1c.ru"; Ctor(); ... #EndRegion ``` -------------------------------- ### Noncompliant Extension Variable Naming Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/extension-variable-prefix.md Extension variables must have a prefix corresponding to the extension's prefix. This example shows a noncompliant naming. ```bsl Var Perem Export; ``` -------------------------------- ### Noncompliant Method Documentation in 1C:Enterprise Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-redundant-parameter-section.md This noncompliant example shows a method with an unnecessary parameter section in its documentation comment. Remove the '// Parameters:' section when documenting methods without parameters. ```bsl // Parameters: // Parameters - Method should not have parameter section Procedure NonComplaint() // empty EndProcedure ``` -------------------------------- ### Noncompliant Transaction Handling in BSL Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/begin-transaction.md This code example demonstrates a noncompliant pattern where `CommitTransaction()` is called directly after `BeginTransaction()`, bypassing necessary error handling. ```bsl BeginTransaction(); CommitTransaction(); ``` -------------------------------- ### Asynchronous Method Execution Patterns in BSL Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/code-after-async-call.md Demonstrates the difference between blocking synchronous calls and non-blocking asynchronous calls using the Await keyword. ```bsl Text = "Warning text"; ShowMessageBox( , Text); Message("Warning is closed"); ``` ```bsl Text = "Warning text"; Await DoMessageBoxAsync(Text); Message("Warning is closed"); ``` -------------------------------- ### Execute Using Older Standard Subsystems Library Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/server-execution-safe-mode.md For Standard Subsystems Library versions earlier than 2.4.1, use SafeModeManager.ExecuteInSafeMode(). ```bsl SafeModeManager.ExecuteInSafeMode() ``` -------------------------------- ### Compliant Event Handler Structure in 1C:Enterprise Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/module-structure-event-regions.md This example demonstrates a compliant structure for an event handler. It uses a specific handler procedure name, such as FormGetProcessing, within the designated #Region EventHandlers. ```bsl #Region EventHandlers Procedure FormGetProcessing(FormType, Parameters, SelectedForm, AdditionalInformation, StandardProcessing) //TODO: Insert the handler content EndProcedure #EndRegion ``` -------------------------------- ### Calculate Using Standard Subsystems Library Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/server-execution-safe-mode.md Use Common.CalculateInSafeMode() from the Standard Subsystems Library for safe calculations. ```bsl Common.CalculateInSafeMode() ``` -------------------------------- ### Non-compliant LIKE Usage in 1C Query Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.ql/markdown/ql-like-expression-with-field.md Avoid using table fields as the right operand for LIKE and ESCAPE operations. This example shows an incorrect query structure. ```bsl SELECT StocksBalanceAndTurnovers.Warehouse FROM AccumulationRegister.Stocks.BalanceAndTurnovers AS StocksBalanceAndTurnovers WHERE StocksBalanceAndTurnovers.Warehouse LIKE Table.Field ``` -------------------------------- ### Correct Variable Names in 1C:Enterprise Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/bsl-variable-name-invalid.md Examples of correctly formatted variable names that adhere to the rules for clarity and convention. Names should be descriptive and follow the camel case convention. ```bsl Var DialogWorkingCatalog; Var NumberOfPacksInTheBox; NewDocumentRef; ``` -------------------------------- ### Avoid Direct Configuration Method Execution (Older Library) Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/server-execution-safe-mode.md Do not use SafeModeManager.ExecuteConfigurationMethod() directly; prefer safe mode execution methods for older library versions. ```bsl SafeModeManager.ExecuteConfigurationMethod() ``` -------------------------------- ### Noncompliant Method Extension Visibility Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/extension-method-visible-mode.md This noncompliant example shows a method extension that might compile in contexts where the source method does not, violating visibility rules. Ensure extensions are conditionally compiled if the source method has specific visibility. ```1c #If Server Then Procedure Server1() Everywhere1(); EndProcedure Procedure Везде1() Export EndProcedure #EndIf Function Test() Export EndFunction Module extension &After("Server1") Procedure Ext1_Server1() Everywhere1(); EndProcedure ``` -------------------------------- ### Noncompliant Documentation Comment Field Use Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-complex-type-with-link.md This noncompliant example shows a documentation comment field linking to a type using 'See NewStructureObject'. Use direct type declarations instead. ```bsl // Parameters: // Parameters - Structure - (See NewStructureObject.) Procedure NonComplaint(Parameters) Export // empty EndProcedure // Returns: // Parameters - Structure: // * Key1 - Number - has type for key Function NewStructureObject() // empty EndFunction ``` -------------------------------- ### Noncompliant BSL documentation comment Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-description-ends-on-dot.md Example of a multi-line comment that fails to end with a period. ```bsl // First line // second line Procedure NonComplaint() Export // empty EndProcedure ``` -------------------------------- ### Avoid Direct Configuration Method Execution Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/server-execution-safe-mode.md Do not use Common.ExecuteConfigurationMethod() directly; prefer safe mode execution methods. ```bsl Common.ExecuteConfigurationMethod() ``` -------------------------------- ### Compliant Parameter Documentation Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-parameter-section.md Correct implementation of parameter documentation for exported and local procedures. ```bsl // Parameters: // Parameters - Structure Procedure Complaint(Parameters) Export // empty EndProcedure // Parameters: // Parameters - local methods may not contains all parameters Procedure Complaint2(Parameters, SecondParameter) // empty EndProcedure ``` -------------------------------- ### Compliant Global Module Names Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.md/markdown/common-module-name-global-client.md Use the 'Global' suffix for global client common modules. Do not append 'Client' if 'Global' is already present. ```text FilesOperationsGlobal, InfobaseUpdateGlobal. ``` -------------------------------- ### Noncompliant: Missing Semicolon in 1C Statement Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/semicolon-missing.md This example shows a procedure where the last statement lacks a semicolon, which is not the preferred style. ```1c Procedure procedureName(Parameters) A = 1 EndProcedure ``` -------------------------------- ### Calculate Using Older Standard Subsystems Library Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/server-execution-safe-mode.md For Standard Subsystems Library versions earlier than 2.4.1, use SafeModeManager.CalculateInSafeMode(). ```bsl SafeModeManager.CalculateInSafeMode() ``` -------------------------------- ### Compliant Method Extension Visibility Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/extension-method-visible-mode.md This compliant solution demonstrates how to correctly scope method extensions using '#If Server Then' to match the visibility of the source method. This prevents compilation errors in contexts where the original method is not accessible. ```1c #If Server Then Procedure Server1() Everywhere1(); EndProcedure Procedure Везде1() Export EndProcedure #EndIf Function Test() Export EndFunction Module extension #If Server Then &After("Server1") Procedure Ext1_Server1() Everywhere1(); EndProcedure #EndIf ``` -------------------------------- ### Noncompliant documentation comment structure Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-field-in-description-suggestion.md Example of an incorrectly formatted documentation comment where the field definition is not properly declared. ```bsl // Parameters // Parameters - Structure - description // * Key1 - this field is part of description Procedure NonComplaint(Parameters) Export // empty EndProcedure ``` -------------------------------- ### Compliant: Semicolon at End of 1C Statement Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/semicolon-missing.md This example demonstrates the preferred style of ending statements with a semicolon in 1C:Enterprise procedures. ```1c Procedure procedureName(Parameters) A = 1; EndProcedure ``` -------------------------------- ### Compliant: Using Additional Properties Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/object-module-export-variable.md This compliant solution shows how to avoid export variables by using 'AdditionalProperties' to pass data, which offers better control and reduces the risk of errors. This is the recommended approach. ```bsl Procedure BeforeWrite(Cancel) If AdditionalProperties.Property("FileConversion") Then ... EndProcedure // calling code FileObject.AdditionalProperties.Insert("FileConversion", True); FileObject.Write(); ``` -------------------------------- ### Use &AtServer Pragma in 1C Procedures Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/form-module-missing-pragma.md Always use the compilation pragma '&AtServer' before procedures in form modules. Absence of this pragma defaults to '&AtServer', which can cause extra server calls and issues on the web client. ```bsl Procedure Server() EndProcedure ``` ```bsl &AtServer Procedure Server() EndProcedure ``` -------------------------------- ### Avoid Direct Object Method Execution (Older Library) Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/server-execution-safe-mode.md Do not use SafeModeManager.ExecuteObjectMethod() directly; prefer safe mode execution methods for older library versions. ```bsl SafeModeManager.ExecuteObjectMethod() ``` -------------------------------- ### Initialize Local Variable With Default Empty Value Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/variable-value-type.md Compliant solution: Initializing a local variable with a default empty value (e.g., 0 for numbers) to satisfy strict type system requirements. ```bsl // @strict-types Procedure Test() Export TestVar = 0; // code here EndProcedure ``` -------------------------------- ### Initialize Module Variable With Default Value and Typed Comments Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/variable-value-type.md Compliant solution: Initializing a module variable in module statements and adding typed inline documentation comments for clarity and adherence to strict typing. ```bsl // @strict-types Var ObjectParameters; // see NewObjectParameters Procedure BeforeWrite(Cancel) If DataExchange.Load Then Return; EndIf; If ValueIsFilled(ObjectParameters.Param1) Then // code here EndIf; EndProcedure // Returns: // Structure: // * Param1 - String - Function NewObjectParameters() Params = New Structure(); Params.Insert("Param1", "String value"); Return Params; EndFunction // Explicitly initialize value in module statements ObjectParameters = NewObjectParameters(); ``` -------------------------------- ### Compliant alternatives for deprecated methods Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/use-non-recommended-method.md Recommended replacements for the noncompliant methods, utilizing modern platform APIs. ```bsl Message = New UserMessage(); Message.Text = ("Text"); Message.Message(); Date = CurrentSessionDate(); OpenForm("CommonForm.CommonForm1"); ``` ```bsl StrFind(Catalog.Name, "Joy"); ``` -------------------------------- ### Compliant refactoring of GoTo usage Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/use-goto-operator.md Recommended approach using a procedure call instead of the GoTo operator to improve code clarity. ```bsl If ChartOfCalculationTypes = Object.ChartOfCalculationTypes Then ProcessChartOfCalculationTypes(); EndIf; ``` -------------------------------- ### Compliant Procedure Documentation Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-procedure-return-section.md Use standard description comments for procedures without specifying return values. ```bsl // Procedure description Procedure Complaint() Export // empty EndProcedure ``` -------------------------------- ### Compliant Procedure Parameter Naming in 1C:Company V8 Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-field-name.md Illustrates correct parameter naming within a 1C:Company V8 procedure. Adhering to these conventions improves code readability and maintainability. ```bsl // Parameters: // Parameters - Structure: // * Name - correct name // Procedure Complaint(Parameters) EndProcedure ``` -------------------------------- ### Compliant Execute Call with Safe Mode Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/server-execution-safe-mode.md Enable safe mode using SetSafeMode(True) before calling Execute to ensure security. ```bsl SetSafeMode(True); Execute(Algorithm); ``` -------------------------------- ### Declare Local Variable Without Initialization Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/variable-value-type.md Noncompliant example: Declaring a local variable within a procedure without initializing it. This violates strict type system rules. ```bsl // @strict-types Procedure Test() Export Var TestVar; // code here EndProcedure ``` -------------------------------- ### Noncompliant Global Module Names Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.md/markdown/common-module-name-global-client.md Avoid using both 'Global' and 'Client' suffixes for global client common modules. Use only the 'Global' suffix. ```text FilesOperationsGlobalClient, InfobaseUpdateGlobalClient. ``` -------------------------------- ### Compliant: Direct String Literals and Parameters in Queries Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.ql/markdown/ql-constants-in-binary-operation.md Use direct string literals or parameters without concatenation for better compatibility. This approach avoids issues during database migration. ```bsl SELECT Products.Name AS Name, "MyGoods" AS Code FROM Catalogs.Products AS Products; ``` ```bsl SELECT Products.Name AS Name, &Parameter AS Code FROM Catalogs.Products AS Products; ``` ```bsl SELECT Products.Name AS Name, FieldName AS Code FROM Catalogs.Products AS Products WHERE FieldName LIKE "123%" ``` -------------------------------- ### Noncompliant GoTo usage Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/not-support-goto-operator-webclient.md Avoid using GoTo in client-side modules as it is incompatible with the web client. ```1C:Enterprise If ChartOfCalculationTypes = Object.ChartOfCalculationTypes Then GoTo ~ChartOfCalculationTypes; EndIf; ``` -------------------------------- ### Noncompliant Event Handler Structure in 1C:Enterprise Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/module-structure-event-regions.md This example shows a noncompliant way to define an event handler. Event handlers should be specific to their purpose and not generic procedures within the #Region EventHandlers. ```bsl #Region EventHandlers Procedure Test() //TODO: Insert the handler content EndProcedure #EndRegion ``` -------------------------------- ### Compliant Execute in Service Mode with Data Separation Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/server-execution-safe-mode.md In service mode, enable safe mode and configure data separation before executing algorithms. ```bsl SetSafeMode(True); For each SeparatorName in ConfigurationSeparators() Do SetDataSeparationSafeMode(SeparatorName, True); EndDo; Execute Algorithm; ``` -------------------------------- ### Compliant: Detailed Exception Handling Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/empty-except-statement.md Log errors to the event log for administrators and provide a user-friendly message. Use WriteLogEvent and Raise for proper error propagation. ```bsl Try // Code that throws an exception .... Except // Writing an event to the event log for the system administrator. WriteLogEvent(NStr("en = 'Executing an operation'"), EventLogLevel.Error,,, DetailErrorDescription(ErrorInfo())); Raise; EndTry; ``` -------------------------------- ### Compliant: Initialize Structure Keys With Default Typed Values Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/structure-consructor-value-type.md Initialize structure keys with default typed values in the constructor or insert new keys with default typed values. This ensures proper type handling throughout the structure's lifecycle. ```bsl // @strict-types Procedure Test() Export Params = new Structure("Key1, Key2", 0, ""); Params.Insert("Key3", Catalogs.Products.EmptyRef()); // some code... Params.Key1 = 1345; Params.Key2 = "New vlaue"; Params.Key3 = Catalogs.Products.Service; EndProcedure ``` -------------------------------- ### Structure constructor with excessive keys Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/structure-consructor-too-many-keys.md Initializes a Structure with more than three keys in the constructor, which is flagged as noncompliant. ```bsl Parameters = new Structure("Key1, Key2, Key3, Key4"); ``` -------------------------------- ### Noncompliant Documentation Comment with Incorrect Dash Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-use-minus.md This example shows a documentation comment using an incorrect long dash (⸺) instead of a hyphen-minus. Ensure only hyphen-minus is used in the description part of documentation comments. ```bsl // Parameters: // Parameters – Structure - first is middle-dash and second is minus: // * Key1 - Number ⸺ incorrect long dash Procedure NonComplaint(Parameters) Export // empty EndProcedure ``` -------------------------------- ### Noncompliant Procedure Documentation Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-procedure-return-section.md Avoid including a 'Returns' section for procedures, as this is syntactically or semantically incorrect for non-returning routines. ```bsl // Returns: // Structure - procedure should not have return section! Procedure NonComplaint() Export // empty EndProcedure ``` -------------------------------- ### Compliant BSL export functions Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-export-function-return-section.md Functions correctly documenting return values using the 'Returns:' section. ```bsl // See Complaint2 Function Complaint() Export // empty EndFunction // Returns: // Structure - Parameters: // * Key1 - Number - has type for key Function Complaint2() Export // empty EndFunction ``` -------------------------------- ### Avoid Direct Object Method Execution Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/server-execution-safe-mode.md Do not use Common.ExecuteObjectMethod() directly; prefer safe mode execution methods. ```bsl Common.ExecuteObjectMethod() ``` -------------------------------- ### Compliant Method with Fewer Parameters Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/method-too-many-params.md This function declares a minimal set of parameters, promoting better readability and maintainability. Additional properties are set directly on the returned object after the function call. ```bsl // Adds a new field to a form and initializes it with default values. Function NewFormField(FieldName) … EndFunction // calling the function NewField = NewFormField("OldPrice" + ColumnName); NewField.Heading = NStr("en='Price'"); NewField.BackColor = BackColor; NewField.TextColor = WebColors.Gray; NewField.… = … … ``` -------------------------------- ### Check access rights in BSL Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/using-isinrole.md Use the AccessRight method to verify permissions based on metadata objects rather than role names. ```bsl If IsInRole("AddClient") Then ... ``` ```bsl If AccessRight("Add", Metadata.Catalogs.Client) Then ... ``` -------------------------------- ### Compliant Eval Call with Safe Mode Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/server-execution-safe-mode.md Enable safe mode using SetSafeMode(True) before calling Eval to ensure security. ```bsl SetSafeMode(True); Eval(Algorithm); ``` -------------------------------- ### Compliant StyleColors usage Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/new-color.md Use predefined style elements from StyleColors to maintain design consistency. ```bsl Color = StyleColors.; ... ``` -------------------------------- ### Compliant attribute access using Query Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/reading-attribute-from-database.md Use a query to explicitly select only the required fields, preventing the overhead of loading the entire object. ```bsl Procedure FillCountryCodeAndDescription() Query = New Query( "SELECT | WorldCountries.Code, | WorldCountries.Description |FROM | Catalog.WorldCountries AS WorldCountries |WHERE | WorldCountries.Ref = &Ref"); Query.SetParameter("Ref", Ref); Selection = Query.Execute().Select(); Selection.Next(); CountryCode = Selection.Code; CountryDescription = Selection.Description; EndProcedure ``` -------------------------------- ### Noncompliant Color instantiation Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/new-color.md Avoid creating new Color objects directly as it prevents consistent styling across the application. ```bsl Color = new Color(0,0,0); ... ``` -------------------------------- ### Non-compliant Execute Call Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/server-execution-safe-mode.md Avoid calling Execute directly without enabling safe mode first to prevent vulnerabilities. ```bsl Execute(Algorithm); ``` -------------------------------- ### Non-compliant Method with Many Parameters Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/method-too-many-params.md This function declares a large number of parameters, including many with default values, which can lead to reduced readability and errors when calling the function. Avoid declaring more than seven parameters, with no more than three having default values. ```bsl // Adds a new field to a form and initializes it with default values. Function AddFormField(Name, Heading = Undefined, OnChangeHandler = "", OnBeginSelectionHandler = "", MarginWidth, Backcolor = Undefined, TitleBackColor = Undefined, Parent = Undefined, HeaderPicture = Undefined, DataPath = Undefined, FieldReadOnly = False, ChoiceParameterLinks = Undefined) … EndFunction // calling the function NewField = AddFormField("OldPrice" + ColumnName, NStr("en='Price'"),,, 12, BackColor, TitleColor, NewFolder,,,True); NewField.TextColor = WebColors.Gray; ``` -------------------------------- ### Compliant: Using FormAttributeToValue Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/using-form-data-to-value.md Prefer FormAttributeToValue for its simpler syntax and automatic data type handling. This method is recommended for consistency with other 1C:Enterprise applications. ```bsl SignaturesTable = FormAttributeToValue("SignaturesTable"); ``` -------------------------------- ### Noncompliant: Empty Except Block Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/empty-except-statement.md Avoid empty except blocks as they hide errors from users and administrators. Always provide a detailed exception presentation. ```bsl Try ExecuteOperation(); Except // error; EndTry; ``` -------------------------------- ### Compliant Link Formatting in Comments Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/link-part-comment-space.md Ensure a space precedes internal links in comments for better readability. This adheres to the recommended style. ```1c //CorrectLink - See Catalogs.Catalog ``` -------------------------------- ### Non-compliant Procedure Parameter Naming in 1C:Company V8 Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-field-name.md Demonstrates incorrect parameter naming within a 1C:Company V8 procedure. Ensure parameter names follow established conventions. ```bsl // Parameters: // Parameters - Structure: // * 1Name - incorrect name // Procedure NonComplaint(Parameters) EndProcedure ``` -------------------------------- ### Compliant: Correct NStr usage Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/bsl-nstr-string-literal-format.md This demonstrates the correct way to use the NStr function with a valid language code and a properly formatted, non-empty string message. ```bsl Procedure Compliant(Message) Export Message = NStr("en = 'User message'"); EndProcedure ``` -------------------------------- ### Compliant attribute access using SSL functions Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/reading-attribute-from-database.md Utilize the Common.ObjectAttributesValues function from the Standard Subsystems Library to simplify attribute retrieval. ```bsl Procedure FillCountryCodeAndDescription() AttributesValues = Common.ObjectAttributesValues(CountryRef, "Code, Description"); CountryCode = AttributesValues.Code; CountryDescription = AttributesValues.Description; EndProcedure ``` -------------------------------- ### Compliant structured control flow Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/not-support-goto-operator-webclient.md Refactor GoTo logic into separate procedures or functions to ensure compatibility. ```1C:Enterprise If ChartOfCalculationTypes = Object.ChartOfCalculationTypes Then ProcessChartOfCalculationTypes(); EndIf; ``` -------------------------------- ### Compliant: Optional parameters after required Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/method-optional-parameter-before-required.md Ensure all optional parameters, which have default values, are listed after the required parameters in function definitions. This adheres to the recommended code style. ```bsl Function ExchangeRateOnDate(Currency, Date = Undefined) Export ``` -------------------------------- ### Compliant Eval in Service Mode with Data Separation Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/server-execution-safe-mode.md In service mode, enable safe mode and configure data separation before evaluating algorithms. ```bsl SetSafeMode(True); For each SeparatorName in ConfigurationSeparators() Do SetDataSeparationSafeMode(SeparatorName, True); EndDo; Eval(Algorithm); ``` -------------------------------- ### Compliant Return Type Specification Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/doc-comment-return-section-type.md Specify clear and known return types in documentation comments. This improves code understanding and tooling support. ```bsl // Parameters: // See Complaint2() Function Complaint(Parameters) Export // empty EndFunction // Parameters: // Structure - has return type Function Complaint2(Parameters) Export // empty EndFunction ``` -------------------------------- ### Compliant: Direct Reference in Common Module Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/common-module-named-self-reference.md For non-cached common modules, directly reference properties and methods without using the module's name (e.g., myParam = test()). This is the preferred approach. ```bsl Var myParam; Function test() Export // code here EndFunction myParam = test(); ``` -------------------------------- ### Noncompliant: Query in Loop Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/query-in-loop.md Avoid executing similar queries within a loop. This approach can lead to significant performance degradation, especially with large datasets. Ensure all necessary parameters are set before execution. ```bsl // BanksToProcessing - contains an array of banks InidividualQuery = New Query; InidividualQuery.Text = "SELECT | BankAccounts.Ref AS Account |FROM | Catalog.BankAccounts AS BankAccounts |WHERE | BankAccounts.Bank = &Bank"); For Each Bank From BanksToProcess Do InidividualQuery .SetParameter("Bank", Bank); AccountsSelection = InidividualQuery .Execute().Select(); While AccountsSelection.Next() Do ProcessBankAccounts(AccountsSelection.Account); EndDo; EndDo; ``` -------------------------------- ### Compliant Transaction Implementation Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/commit-transaction.md Wrap the transaction logic within a try-catch block to ensure that any errors trigger a rollback. ```bsl BeginTransaction(); Try // ... CommitTransaction(); Except // ... RollbackTransaction(); // ... Raise; EndTry; ``` -------------------------------- ### Compliant Structure Key Modification Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/structure-key-modification.md Access existing keys directly to set new values. Instead of deleting a key, assign a value that represents a blank or initial state. ```bsl // @strict-types Procedure Correct1() Export TestStucture = Constructor(); TestStucture.Key1 = false; TestStucture.Key2 = -1; EndProcedure // Returns: // Structure: // * Key1 - Boolean - // * Key2 - Number - Function Constructor() Export TestStucture = new Structure("Key1, Key2", true, 10); TestStucture.Insert("Key2", 10); Return TestStucture; EndFunction ``` -------------------------------- ### Compliant Form Event Handlers with Shared Logic Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/invocation-form-event-handler.md Use separate, dedicated procedures for event handling and a common server procedure for shared logic. This improves code organization and stability by clearly separating concerns. ```bsl &AtClient Procedure ByPerformerOnChange(Item) SetFilter(); EndProcedure &AtClient Procedure ByAuthorOnChange(Item) SetFilter(); EndProcedure &AtServer Procedure SetFilter() FilterParameters = New Map(); FilterParameters.Insert("ByAuthor", ByAuthor); FilterParameters.Insert("ByPerformer", ByPerformer); SetListFilter(List, FilterParameters); EndProcedure ``` -------------------------------- ### Compliant Event Handler Logic with Logical OR Source: https://github.com/1c-company/v8-code-style/blob/master/bundles/com.e1c.v8codestyle.bsl/markdown/event-heandler-boolean-param.md A concise way to handle the 'Cancel' parameter is to use the logical OR operator. This ensures that 'Cancel' remains true if it was already set to true by a previous check or subscription. ```bsl Cancel = Cancel Or IsFilleCheckError(); ```