1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- module.exports = class DetectTranslatableString
-
- rule:
- name: 'detect_translatable_string'
- level: 'ignore'
- message: 'The following string looks like it should be marked as translatable via __(...)'
- description: '''
- '''
- constructor: ->
- @callTokens = []
- tokens: ['STRING', 'CALL_START', 'CALL_END']
- lintToken: (token, tokenApi) ->
- [type, tokenValue] = token
- if type in ['CALL_START', 'CALL_END']
- @trackCall token, tokenApi
- return
- return false if @isInIgnoredMethod()
- return @lintString(token, tokenApi)
- lintString: (token, tokenApi) ->
- [type, tokenValue] = token
-
- string = tokenValue[1..-2]
-
- return false if string.split(' ').length < 2
-
- return false if tokenApi.peek(-3)[1] == 'throw'
- return false if tokenApi.peek(-2)[1] == 'throw'
- return false if tokenApi.peek(-1)[1] == 'throw'
-
- return false if tokenApi.peek(-1)[1] == '=='
-
- return false if tokenApi.peek(1)[1] == '+'
- return false if tokenApi.peek(2)[1] == '+'
- BLOCKLIST = [
-
- /^[^A-Z]/,
-
-
- ]
- return false if BLOCKLIST.some (entry) ->
-
- string.match(entry)
-
-
-
-
- return { context: "Found: #{token[1]}" }
- ignoredMethods: {
- '__': true,
- 'log': true,
- 'T': true,
- 'controllerBind': true,
- 'debug': true,
- 'error': true,
- 'set': true,
- 'translateInline': true,
- 'translateContent': true,
- 'translatePlain': true,
- }
- isInIgnoredMethod: ->
-
- for t in @callTokens
- return true if t.isIgnoredMethod
- return false
- trackCall: (token, tokenApi) ->
- if token[0] is 'CALL_START'
- p = tokenApi.peek(-1)
- token.isIgnoredMethod = p and @ignoredMethods[p[1]]
- @callTokens.push(token)
- else
- @callTokens.pop()
- return null
|