All the Software developers of Netspective Communications LLC across all the projects
must have a consistent code formatting process.
Controls
All are required to adhere to the formatting tool that aligns with their development or runtime technology listed below.
Runtime Language | Formatting Tool | Remarks |
---|---|---|
Node.js | Prettier | The same can be used for Node.js, TypeScript, React, Angular, Astro Projects |
Deno | built-in code formatter | builtin deno fmt formatter |
Python | black | black as a formatter tool for Python Projects |
PostgreSQL SQL | pgFormatter | https://sqlformat.darold.net/ |
Node.js
All developers who use Node.js as a runtime for their programming language must use Prettier as the formatting tool. [FII-CQI-060-CFP-01]
-
Ensure to execute the below command in the CLI to install prettier globally.
npm install -g prettier
[FII-CQI-060-CFP-01.1]
-
Ensure to run the following command in CLI to install the packages needed for prettier
npm install --save-dev prettier prettier-eslint
[FII-CQI-060-CFP-01.2]
-
Ensure to add the below provided content to package.json to format the project using the ‘npm run format’ command
"scripts": { "format": "npx prettier --write \"**/*.{cjs,js,jsx,ts,tsx}\"", },
[FII-CQI-060-CFP-01.3]
-
Ensure
npm run format
command will run to format with prettier in the whole project. [FII-CQI-060-CFP-01.4] -
Ensure to enable the extension “Prettier- Code formatter” v9.10.4 or later in Visual Studio Code. [FII-CQI-060-CFP-01.5]
-
Ensure to use
prettier --write .
command to format all files in the current directory and its subdirectories. [FII-CQI-060-CFP-01.6] -
Ensure to add default formatter and formatOnSave options in .vscode/settings.json from the root directory.
{ "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true }
[FII-CQI-060-CFP-01.7]
- Ensure to add and modify the configuration file
.prettierrc.cjs
and ensure rules must matches Deno formatting rule.
[FII-CQI-060-CFP-01.8]module.exports = { semi: true, useTabs: false, trailingComma: "all", singleQuote: false, printWidth: 80, tabWidth: 2, };
- All React developers must ensure they are following React reference Project for React code quality.
Deno
All the developers who uses Deno as a runtime for their programming language must use deno fmt as the formatting tool. [FII-CQI-060-CFP-02]
SQL
All the developers who writes or generates SQL must use pgFormatter and the VSCode extension https://marketplace.visualstudio.com/items?itemName=bradymholt.pgformatter. [FII-CQI-060-CFP-03]
Python
All Python developers must ensure they use Black for code formatting. [FII-CQI-060-CFP-04]
-
All Python developers must ensure they follow the steps below to integrate Black with PyCharm:
` $ pip install black` Open External tools in PyCharm via File -> Settings -> Tools -> External Tools Click the + icon to add a new external tool with the following values: Name: Black Description: Black is the uncompromising Python code formatter. Program: <install_location_from_step_2> Arguments: $FilePath$ Working directory: $ProjectFileDir$ Save the external tool configuration: Click "OK" to save the external tool configuration.
[FII-CQI-060-CFP-04-01]
Evidence
- A quality resource will run the below duckdb query on each developer’s CLI every week to ensure that all of the queries return a true result.
- An udi-pgp-sqld agent will be created and export these output to a CSV
Node.js
[FII-CQI-060-CFP-01.2] Execute the below duckdb query in a CLI to verify package.json contains prettier@2.8.4
or later and prettier-eslint@15.0.0
or later.
duckdb -s "SELECT devDependencies->'prettier', devDependencies->'prettier-eslint' FROM read_json_auto('package.json');"
[FII-CQI-060-CFP-01.3] Execute the below duckdb query in a CLI to verify package.json contains format
command.
duckdb -s "(SELECT name,type,version,scripts->>'format' FROM read_json_auto('package.json'));"
[FII-CQI-060-CFP-01.4] Execute the below duckdb query in the CLI to run format
command and output formatted result as SQL.
duckdb -s "SELECT UNNEST(regexp_split_to_array('$(npm run format -- -c )', '\n')) as 'Format Result';"
ensure getting output as
All matched files use Prettier code style!
[FII-CQI-060-CFP-01.5] Execute the below query in the CLI to check whether prettier plugin for vscode is installed or not.
duckdb -s "SELECT COUNT(*) as 'esbenp.prettier-vscode' FROM (SELECT '$(code --list-extensions --show-versions)' as 'ext_res') WHERE ext_res LIKE '%esb
enp.prettier-vscode%';"
[FII-CQI-060-CFP-01.7] Execute the below given duckdb query in a CLI to verify formatOnSave and default formatter is enabled in .vscode/settings.json
duckdb -s 'SELECT "editor.formatOnSave","editor.defaultFormatter" FROM read_json_auto(".vscode//settings.json") ; '
Use the below query to export all format related evidence in a single file.
duckdb -s "SELECT filename, name,type,version,scripts->>'format',\"editor.formatOnSave\" as fos,\"editor.defaultFormatter\" as df,'$(lsb_release -a)' as os_details FROM read_json_auto(['.vscode/settings.json','package.json'],union_by_name=True, filename=True);"
One Sample output is
File Name | Project Name | Project Type | Version | Format Script | Format On Save | Editor Formatter | OS Details |
---|---|---|---|---|---|---|---|
.vscode/settings.j… | true | esbenp.prettier-vs… | Distributor ID: Ubuntu\nDescrip… | ||||
package.json | @example/docs | module | 0.0.1 | npx prettier —wri… | Distributor ID: Ubuntu\nDescrip… |