File Parser.js
has 670 lines of code (exceeds 250 allowed). Consider refactoring. Open
import tokenize from 'tokenize-sync'
import color from 'color'
import validateDeclaration from './validateDeclaration'
import validateFunction from './validateFunction'
Function parseDeclaration
has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring. Open
parseDeclaration() {
if (this.currentToken.type === 'identifier') {
const propertyToken = this.currentToken
const property = propertyToken.value
const isRawDeclaration = property.substr(0, 2) === '__'
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function parseDeclaration
has 104 lines of code (exceeds 25 allowed). Consider refactoring. Open
parseDeclaration() {
if (this.currentToken.type === 'identifier') {
const propertyToken = this.currentToken
const property = propertyToken.value
const isRawDeclaration = property.substr(0, 2) === '__'
Function parse
has 76 lines of code (exceeds 25 allowed). Consider refactoring. Open
parse(input) {
this.tokens = tokenize(input.trim(), ruleMap, 'unknown').filter(
(token) => token.type !== 'whitespace'
)
Parser
has 22 functions (exceeds 20 allowed). Consider refactoring. Open
export default class Parser {
constructor(config = {}) {
this.config = config
this.context = config.context || {}
}
Function parseCondition
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
parseCondition() {
const property = this.parseIdentifier() || this.parseVariable()
if (property) {
this.updateCurrentToken(1)
Function parseCondition
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
parseCondition() {
const property = this.parseIdentifier() || this.parseVariable()
if (property) {
this.updateCurrentToken(1)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function parseVariantBody
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
parseVariantBody() {
const body = []
if (
this.currentToken.type === 'curly_bracket' &&
Function parseVariant
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
parseVariant() {
if (
this.currentToken.type === 'identifier' &&
this.currentToken.value === 'variant'
) {
Function parseStyle
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
parseStyle() {
if (
this.currentToken.type === 'identifier' &&
this.currentToken.value === 'style'
) {
Function parseStyleBody
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
parseStyleBody() {
const body = []
if (
this.currentToken.type === 'curly_bracket' &&
Function parseConditional
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
parseConditional() {
if (
this.currentToken.type === 'square_bracket' &&
this.currentToken.value === '['
) {
Function parseVariantBody
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
parseVariantBody() {
const body = []
if (
this.currentToken.type === 'curly_bracket' &&
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function parseNumber
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
parseNumber(isNegative = false) {
if (this.currentToken.type === 'number') {
const integer = this.currentToken.value
const nextToken = this.getNextToken(1)
Function parseIdentifier
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
parseIdentifier() {
if (this.currentToken.type === 'identifier') {
const ident = this.currentToken.value
const nextToken = this.getNextToken(1)
if (nextToken.type === 'round_bracket' && nextToken.value === '(') {
Function parseStyleBody
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
parseStyleBody() {
const body = []
if (
this.currentToken.type === 'curly_bracket' &&
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function parse
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
parse(input) {
this.tokens = tokenize(input.trim(), ruleMap, 'unknown').filter(
(token) => token.type !== 'whitespace'
)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function parseVariant
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
parseVariant() {
if (
this.currentToken.type === 'identifier' &&
this.currentToken.value === 'variant'
) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
if (validation.type === 'property') {
this.addError(
{
type: errorTypes.INVALID_PROPERTY,
property: property,
Avoid deeply nested control flow statements. Open
if (
validation.type === 'value' &&
value.type !== 'Variable' &&
value.type !== 'RawValue'
) {
Function parseConditional
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
parseConditional() {
if (
this.currentToken.type === 'square_bracket' &&
this.currentToken.value === '['
) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function parseStyle
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
parseStyle() {
if (
this.currentToken.type === 'identifier' &&
this.currentToken.value === 'style'
) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function parseNumber
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
parseNumber(isNegative = false) {
if (this.currentToken.type === 'number') {
const integer = this.currentToken.value
const nextToken = this.getNextToken(1)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function parseIdentifier
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
parseIdentifier() {
if (this.currentToken.type === 'identifier') {
const ident = this.currentToken.value
const nextToken = this.getNextToken(1)
if (nextToken.type === 'round_bracket' && nextToken.value === '(') {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Similar blocks of code found in 2 locations. Consider refactoring. Open
property +
': ' +
value.value +
'\n' +
' '.repeat(property.length + 2) +
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 77.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
property +
': ' +
value.value +
'\n^-------\n' +
'The property ' +
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 77.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (name && name.charAt(0).toUpperCase() !== name.charAt(0)) {
this.addError(
{
type: errorTypes.SYNTAX_ERROR,
message: 'Variant names must begin with an uppercase letter.',
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 70.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (name && name.charAt(0).toUpperCase() !== name.charAt(0)) {
this.addError(
{
type: errorTypes.SYNTAX_ERROR,
message: 'A style name must begin with an uppercase letter.',
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 70.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76