Table des matières

Tidy

To make documents clean, we did automate reformatting with tools freely available

Tidy Code

To keep the code clean, follow this guide (but dont worry if you dont!)

Tools

Installation

Cpan minus (cpanm) install the latest package, but this can break be in conflict with OS package manager.

cpanm install Perl::Tidy
cpanm install Perl::Critic
cpanm install Code::TidyAll

Usage

“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 understand what it does.

To simulate the result:

tidyall -a --check-only 

To make it work (perltidy will reformat files with an inplace reformatting, perlcritic will review code, but do not change any files)

tidyall -a 

And files are bakuped ind the “.tidyall.d” folder (add it to your git ignore files, if not already)

Current Best Practice with Perltidy

(Can change at any time: submit your proposal, critics)
Similar to arg -pbp (perl best practice), mainly:

Best Practice for Critic

(Wip, Not Implemented, nor deployed)

Use modern default:

Tidy Document

To keep clean the other documents that are not code, follow this guide (but dont worry if you dont!)

Tools

Current Best Practice with autoformat

Installation

Cpan minus (cpanm) install the latest package, but this can break be in conflict with OS package manager.

cpanm install Text::Autoformat

Create the following script: (I named it: autoformat.pl)

#!/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;

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

chmod +x autoformat.pl

And test it!

autoformat.pl < unformated.txt > formated.txt
autoformat.pl < unformated.md > formated.md