File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,25 @@ module.exports = (str) => {
18
18
return array . join ( '\n' ) ;
19
19
} ;
20
20
21
+ module . exports . isAligned = ( str ) => {
22
+ check ( str ) ;
23
+
24
+ const array = str . split ( '\n' ) ;
25
+ const n = array . length - 1 ;
26
+
27
+ for ( let i = 0 ; i < n ; i ++ ) {
28
+ const str = array [ i ] ;
29
+
30
+ if ( ! i || isNotSpaceString ( str ) )
31
+ continue ;
32
+
33
+ if ( str !== getSpaces ( array [ i + 1 ] ) )
34
+ return false ;
35
+ }
36
+
37
+ return true ;
38
+ } ;
39
+
21
40
function isNotSpaceString ( s ) {
22
41
let i = s . length ;
23
42
Original file line number Diff line number Diff line change @@ -29,3 +29,24 @@ test('align-spaces', (t) => {
29
29
t . end ( ) ;
30
30
} ) ;
31
31
32
+ test ( 'align-spaces: isAligned' , ( t ) => {
33
+ const result = alignSpaces . isAligned ( notAligned ) ;
34
+
35
+ t . notOk ( result , 'should be false' ) ;
36
+ t . end ( ) ;
37
+ } ) ;
38
+
39
+ test . only ( 'align-spaces: isAligned: ok' , ( t ) => {
40
+ debugger ;
41
+ const result = alignSpaces . isAligned ( [
42
+ 'function calc() {' ,
43
+ ' const result = [];' ,
44
+ ' ' ,
45
+ ' return result;' ,
46
+ '}'
47
+ ] . join ( '\n' ) ) ;
48
+
49
+ t . ok ( result , 'should be true' ) ;
50
+ t . end ( ) ;
51
+ } ) ;
52
+
You can’t perform that action at this time.
0 commit comments