User Tools

Site Tools


en:devmon:guidelines:tidy

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:devmon:guidelines:tidy [2021/08/13 14:01] – [Current Best Practice for Tidy] Bruno Manzonien:devmon:guidelines:tidy [2021/08/22 14:35] (current) – [Tidy Document] adminw1k1
Line 1: Line 1:
 ====== Tidy ====== ====== Tidy ======
  
-To make it easier to keep code clean, you can follow this guide +To make documents clean, we did automate reformatting with tools freely available 
  
-Objective+==== Tidy Code ==== 
 + 
 +To keep the code clean, follow this guide (but dont worry if you dont!) 
 + 
 +=== Tools===
   *Tidy perl code, ... (perltidy)   *Tidy perl code, ... (perltidy)
   *Follow best practice (perlcritic)   *Follow best practice (perlcritic)
   *Automate it (tidyall)   *Automate it (tidyall)
  
-Installation  +=== Installation ===  
-Cpan minus (cpanm) install latest package, but this can break be in conflict with OS package manager. Make a backup if you can first.+Cpan minus (cpanm) install the latest package, but this can break be in conflict with OS package manager. 
  
 <code> <code>
Line 16: Line 20:
 cpanm install Code::TidyAll cpanm install Code::TidyAll
 </code> </code>
 +
 +==== Usage ====
  
 "TidyAll" automates the code formating (perltidy) and the code review (perlcritic). "TidyAll" automates the code formating (perltidy) and the code review (perlcritic).
-In the project folder, you will find a file called: **".tidyallrc"** that contains the current configuration. Look at it to undestand what it does.+In the project folder, you will find a file called: **".tidyallrc"** that contains the current configuration. Look at it to understand what it does.
 \\ \\
 \\ \\
Line 28: Line 34:
 To make it work (perltidy will reformat files with an inplace reformatting, perlcritic will review code, but do not change any files)  To make it work (perltidy will reformat files with an inplace reformatting, perlcritic will review code, but do not change any files) 
  
-To simulate the result:  
 <code> <code>
 tidyall -a  tidyall -a 
 </code> </code>
  
-And files are bakuped ind the ".tidyall.d" folder (add it to your git ignore files, if not already)+And files are bakuped ind the **".tidyall.d"** folder (add it to your git ignore files, if not already)
  
  
-===== Current Best Practice for Tidy ===== +==== Current Best Practice with Perltidy ==== 
 (Can change at any time: submit your proposal, critics) (Can change at any time: submit your proposal, critics)
 \\ \\
Line 48: Line 53:
    
  
-===== Best Practice for Critic ===== +==== Best Practice for Critic ==== 
 (Wip, Not Implemented, nor deployed) (Wip, Not Implemented, nor deployed)
-=== Use modern default: ===+== Use modern default: ==
   * use strict;   * use strict;
   * use warning;   * use warning;
   * use utf8;   * use utf8;
 +
 +==== Tidy Document ====
 +
 +To keep clean the other documents that are not code, follow this guide (but dont worry if you dont!)
 +
 +
 +=== Tools===
 +
 +  * Autoformat
 +
 +=== Current Best Practice with autoformat === 
 +  * 78 char per line
 +  * (stating at pos 0)
 +
 +=== Installation === 
 +Cpan minus (cpanm) install the latest package, but this can break be in conflict with OS package manager.
 +<code>
 +cpanm install Text::Autoformat
 +</code>
 +
 +Create the following script: (I named it: autoformat.pl)
 +<code>
 +#!/usr/bin/perl -w
 +# Minimal use: read from STDIN, format to STDOUT...
 +use strict;
 +use Text::Autoformat;
 +my $str = do { local $/; <STDIN> };
 +my $out = autoformat $str, {left=>0, right=>78, all=>1};
 +print $out;
 +</code>
 +
 +And now you can format any text or markdown (this will not rendered in a Markdown reader, but Markdown files becomes more readable when they are read "without" a Markdown reader. (like basic vi , less and other standard tools) 
 +
 +Make your script exectutable
 +<code>
 +chmod +x autoformat.pl
 +</code>
 +
 +And test it!
 +
 +<code>
 +autoformat.pl < unformated.txt > formated.txt
 +autoformat.pl < unformated.md > formated.md
 +</code>
 +
 +
 +
 +
en/devmon/guidelines/tidy.1628856088.txt.gz · Last modified: 2021/08/13 14:01 by Bruno Manzoni