1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/CodeLayout/ProhibitHardTabs.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::CodeLayout::ProhibitHardTabs;
15 use Perl::Critic::Utils qw{ :booleans :severities };
16 use base 'Perl::Critic::Policy';
18 our $VERSION = '1.088';
20 #-----------------------------------------------------------------------------
22 Readonly::Scalar my $DESC => q{Hard tabs used};
23 Readonly::Scalar my $EXPL => [ 20 ];
25 my $DEFAULT_ALLOW_LEADING_TABS = $TRUE;
27 #-----------------------------------------------------------------------------
29 sub supported_parameters {
32 name => 'allow_leading_tabs',
33 description => 'Allow hard tabs before first non-whitespace character.',
34 default_string => '1',
35 behavior => 'boolean',
40 sub default_severity { return $SEVERITY_MEDIUM }
41 sub default_themes { return qw( core cosmetic ) }
42 sub applies_to { return 'PPI::Token' }
44 #-----------------------------------------------------------------------------
47 my ( $self, $elem, undef ) = @_;
48 $elem =~ m{ \t }mx || return;
50 # The __DATA__ element is exempt
51 return if $elem->parent->isa('PPI::Statement::Data');
53 # Permit leading tabs, if allowed
54 return if $self->_allow_leading_tabs() && $elem->location->[1] == 1;
56 # Must be a violation...
57 return $self->violation( $DESC, $EXPL, $elem );
60 #-----------------------------------------------------------------------------
62 sub _allow_leading_tabs {
65 return $self->{_allow_leading_tabs};
72 #-----------------------------------------------------------------------------
76 Perl::Critic::Policy::CodeLayout::ProhibitHardTabs - Use spaces instead of tabs.
80 This Policy is part of the core L<Perl::Critic> distribution.
85 Putting hard tabs in your source code (or POD) is one of the worst
86 things you can do to your co-workers and colleagues, especially if
87 those tabs are anywhere other than a leading position. Because
88 various applications and devices represent tabs differently, they can
89 cause you code to look vastly different to other people. Any decent
90 editor can be configured to expand tabs into spaces. L<Perl::Tidy>
91 also does this for you.
93 This Policy catches all tabs in your source code, including POD,
94 quotes, and HEREDOCs. The contents of the C<__DATA__> section are not
99 Tabs in a leading position are allowed, but if you want to forbid all tabs
100 everywhere, put this to your F<.perlcriticrc> file:
102 [CodeLayout::ProhibitHardTabs]
103 allow_leading_tabs = 0
107 Beware that Perl::Critic may report the location of the string that
108 contains the tab, not the actual location of the tab, so you may need
109 to do some hunting. I'll try and fix this in the future.
113 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
117 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
119 This program is free software; you can redistribute it and/or modify
120 it under the same terms as Perl itself. The full text of this license
121 can be found in the LICENSE file included with this module.
125 ##############################################################################
128 # cperl-indent-level: 4
130 # indent-tabs-mode: nil
131 # c-indentation-style: bsd
133 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :