Skip to main content
formatting, tags
Source Link
chaos
  • 49.3k
  • 11
  • 127
  • 147

I am using a tool to calculate cylomatic complexity of a javascript file.

Example -:

$ jsc --minimal test.js

jsc --minimal test.js

thisThis command will give the following output.

┌─────────────────────┬─────┬────────────┬─────────────────────┐
│ File                │ LOC │ Cyclomatic │ Halstead difficulty │
├─────────────────────┼─────┼────────────┼─────────────────────┤
│ /home/shray/test.js │ 23  │ 4          │ 10                  │
└─────────────────────┴─────┴────────────┴─────────────────────┘
Cyclomatic: min 4 mean 4.0 max 4
Halstead: min 10 mean 10.0 max 10

Now I use

$ jsc --minimal test.js | grep "Cyclomatic:"

jsc --minimal test.js | grep "Cyclomatic:"

which gives me output as

Cyclomatic: min 4 mean 4.0 max 4

Now I have a regex, Cyclomatic:[\s]*min[\s]+([0-9]+) but I am not able to use it to extract the number showing minimum Cylomatic value.

Any help how can I just ouput the value of Min or Max Cyclomatic complexity value on the terminal output?

I am using a tool to calculate cylomatic complexity of a javascript file.

Example -

$ jsc --minimal test.js

this command will give the following output.

┌─────────────────────┬─────┬────────────┬─────────────────────┐
│ File                │ LOC │ Cyclomatic │ Halstead difficulty │
├─────────────────────┼─────┼────────────┼─────────────────────┤
│ /home/shray/test.js │ 23  │ 4          │ 10                  │
└─────────────────────┴─────┴────────────┴─────────────────────┘
Cyclomatic: min 4 mean 4.0 max 4
Halstead: min 10 mean 10.0 max 10

Now I use

$ jsc --minimal test.js | grep "Cyclomatic:"

which gives me output as

Cyclomatic: min 4 mean 4.0 max 4

Now I have a regex, Cyclomatic:[\s]*min[\s]+([0-9]+) but I am not able to use it to extract the number showing minimum Cylomatic value.

Any help how can I just ouput the value of Min or Max Cyclomatic complexity value on the terminal output?

I am using a tool to calculate cylomatic complexity of a javascript file.

Example:

jsc --minimal test.js

This command will give the following output.

┌─────────────────────┬─────┬────────────┬─────────────────────┐
│ File                │ LOC │ Cyclomatic │ Halstead difficulty │
├─────────────────────┼─────┼────────────┼─────────────────────┤
│ /home/shray/test.js │ 23  │ 4          │ 10                  │
└─────────────────────┴─────┴────────────┴─────────────────────┘
Cyclomatic: min 4 mean 4.0 max 4
Halstead: min 10 mean 10.0 max 10

Now I use

jsc --minimal test.js | grep "Cyclomatic:"

which gives me output as

Cyclomatic: min 4 mean 4.0 max 4

Now I have a regex, Cyclomatic:[\s]*min[\s]+([0-9]+) but I am not able to use it to extract the number showing minimum Cylomatic value.

Any help how can I just ouput the value of Min or Max Cyclomatic complexity value on the terminal output?

Source Link
Shray
  • 115
  • 4

Using Regex from command line to extract number

I am using a tool to calculate cylomatic complexity of a javascript file.

Example -

$ jsc --minimal test.js

this command will give the following output.

┌─────────────────────┬─────┬────────────┬─────────────────────┐
│ File                │ LOC │ Cyclomatic │ Halstead difficulty │
├─────────────────────┼─────┼────────────┼─────────────────────┤
│ /home/shray/test.js │ 23  │ 4          │ 10                  │
└─────────────────────┴─────┴────────────┴─────────────────────┘
Cyclomatic: min 4 mean 4.0 max 4
Halstead: min 10 mean 10.0 max 10

Now I use

$ jsc --minimal test.js | grep "Cyclomatic:"

which gives me output as

Cyclomatic: min 4 mean 4.0 max 4

Now I have a regex, Cyclomatic:[\s]*min[\s]+([0-9]+) but I am not able to use it to extract the number showing minimum Cylomatic value.

Any help how can I just ouput the value of Min or Max Cyclomatic complexity value on the terminal output?