blib/lib/Code/TidyAll/Plugin/JSHint.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 44 CC 3 SCAR 13.3
CC
3
Cov
0%
validate_file
6.0
_config_file_argv
6.0
_build_cmd
2.0
CRAP 3.8
1 package Code::TidyAll::Plugin::JSHint;
2  
3 use strict;
4 use warnings;
5  
6 use Specio::Library::String;
7  
8 use Moo;
9  
10 extends 'Code::TidyAll::Plugin';
11  
12 has options => (
13 is => 'ro',
14 isa => t('NonEmptyStr'),
15 predicate => '_has_options',
16 );
17  
18 with qw( Code::TidyAll::Role::RunsCommand Code::TidyAll::Role::Tempdir );
19  
20 our $VERSION = '0.83';
21  
22 sub _build_cmd {'jshint'}
23  
24 sub validate_file {
25 my ( $self, $file ) = @_;
26  
27 my $output = $self->_run_or_die( $self->_config_file_argv, $file );
28 if ( $output =~ /\S/ ) {
29 $output =~ s/^$file:\s*//gm;
30 die "$output\n";
31 }
32  
33 return;
34 }
35  
36 sub _config_file_argv {
37 my $self = shift;
38  
39 return unless $self->_has_options;
40  
41 my $conf_file = $self->_tempdir->child('jshint.json');
42 $conf_file->spew(
43 '{ ' . join( ",\n", map {qq["$_": true]} split /\s+/, $self->options ) . ' }' );
44  
45 return ( '--config', $conf_file );
46 }
47  
48 1;
49  
50 # ABSTRACT: Use jshint with tidyall
51  
52 __END__
53  
54 =pod
55  
56 =encoding UTF-8
57  
58 =head1 NAME
59  
60 Code::TidyAll::Plugin::JSHint - Use jshint with tidyall
61  
62 =head1 VERSION
63  
64 version 0.83
65  
66 =head1 SYNOPSIS
67  
68 In configuration:
69  
70 ; With default settings
71 ;
72 [JSHint]
73 select = static/**/*.js
74  
75 ; Specify options inline
76 ;
77 [JSHint]
78 select = static/**/*.js
79 options = bitwise camelcase latedef
80  
81 ; or refer to a jshint.json config file in the same directory
82 ;
83 [JSHint]
84 select = static/**/*.js
85 argv = --config $ROOT/jshint.json
86  
87 where jshint.json looks like
88  
89 {
90 "bitwise": true,
91 "camelcase": true,
92 "latedef": true
93 }
94  
95 =head1 DESCRIPTION
96  
97 Runs L<jshint|http://www.jshint.com/>, a JavaScript validator, and dies if any
98 problems were found.
99  
100 =head1 INSTALLATION
101  
102 See installation options at L<jshint|http://www.jshint.com/platforms/>. One
103 easy method is to install L<npm|https://npmjs.org/>, then run
104  
105 npm install jshint -g
106  
107 =head1 CONFIGURATION
108  
109 This plugin accepts the following configuration options:
110  
111 =head2 argv
112  
113 Arguments to pass to C<jshint>.
114  
115 =head2 cmd
116  
117 The path for the C<jshint> command. By default this is just C<jshint>, meaning
118 that the user's C<PATH> will be searched for the command.
119  
120 =head2 options
121  
122 A whitespace separated string of options, as L<documented by
123 jshint|http://www.jshint.com/docs/>. These will be written to a temporary
124 config file and passed as C<--config> argument.
125  
126 =head1 SUPPORT
127  
128 Bugs may be submitted at L<https://github.com/houseabsolute/perl-code-tidyall/issues>.
129  
130 =head1 SOURCE
131  
132 The source code repository for Code-TidyAll can be found at L<https://github.com/houseabsolute/perl-code-tidyall>.
133  
134 =head1 AUTHORS
135  
136 =over 4
137  
138 =item *
139  
140 Jonathan Swartz <swartz@pobox.com>
141  
142 =item *
143  
144 Dave Rolsky <autarch@urth.org>
145  
146 =back
147  
148 =head1 COPYRIGHT AND LICENSE
149  
150 This software is copyright (c) 2011 - 2022 by Jonathan Swartz.
151  
152 This is free software; you can redistribute it and/or modify it under
153 the same terms as the Perl 5 programming language system itself.
154  
155 The full text of the license can be found in the
156 F<LICENSE> file included with this distribution.
157  
158 =cut