Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
223 changes: 223 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
# This file contains the configuration for Credo and you are probably reading
# this after creating it with `mix credo.gen.config`.
#
# If you find anything wrong or unclear in this file, please report an
# issue on GitHub: https://github.com/rrrene/credo/issues
#
%{
#
# You can have as many configs as you like in the `configs:` field.
configs: [
%{
#
# Run any config using `mix credo -C <name>`. If no config name is given
# "default" is used.
#
name: "default",
#
# These are the files included in the analysis:
files: %{
#
# You can give explicit globs or simply directories.
# In the latter case `**/*.{ex,exs}` will be used.
#
included: [
"examples/",
"lib/",
"src/",
"test/"
],
excluded: [~r"/lib/mix", ~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
},
#
# Load and configure plugins here:
#
plugins: [],
#
# If you create your own checks, you must specify the source files for
# them here, so they can be loaded by Credo before running the analysis.
#
requires: [],
#
# If you want to enforce a style guide and need a more traditional linting
# experience, you can change `strict` to `true` below:
#
strict: true,
#
# To modify the timeout for parsing files, change this value:
#
parse_timeout: 5000,
#
# If you want to use uncolored output by default, you can change `color`
# to `false` below:
#
color: true,
#
# You can customize the parameters of any check by adding a second element
# to the tuple.
#
# To disable a check put `false` as second element:
#
# {Credo.Check.Design.DuplicatedCode, false}
#
checks: %{
enabled: [
#
## Consistency Checks
#
{Credo.Check.Consistency.ExceptionNames, []},
{Credo.Check.Consistency.LineEndings, []},
{Credo.Check.Consistency.ParameterPatternMatching, []},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
{Credo.Check.Consistency.SpaceAroundOperators, []},
{Credo.Check.Consistency.SpaceInParentheses, []},
{Credo.Check.Consistency.TabsOrSpaces, []},

#
## Design Checks
#
# You can customize the priority of any check
# Priority values are: `low, normal, high, higher`
#
{Credo.Check.Design.AliasUsage,
[priority: :normal, if_nested_deeper_than: 1, if_called_more_often_than: 0]},
{Credo.Check.Design.TagFIXME, []},
# You can also customize the exit_status of each check.
# If you don't want TODO comments to cause `mix credo` to fail, just
# set this value to 0 (zero).
#
{Credo.Check.Design.TagTODO, [exit_status: 2]},

#
## Readability Checks
#
{Credo.Check.Readability.AliasOrder, []},
{Credo.Check.Readability.FunctionNames, []},
{Credo.Check.Readability.LargeNumbers, []},
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
{Credo.Check.Readability.ModuleAttributeNames, []},
{Credo.Check.Readability.ModuleDoc, []},
{Credo.Check.Readability.ModuleNames, []},
{Credo.Check.Readability.ParenthesesInCondition, []},
# {Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
{Credo.Check.Readability.PipeIntoAnonymousFunctions, []},
{Credo.Check.Readability.PredicateFunctionNames, []},
{Credo.Check.Readability.PreferImplicitTry, []},
{Credo.Check.Readability.RedundantBlankLines, []},
{Credo.Check.Readability.Semicolons, []},
{Credo.Check.Readability.SpaceAfterCommas, []},
{Credo.Check.Readability.StringSigils, []},
{Credo.Check.Readability.TrailingBlankLine, []},
{Credo.Check.Readability.TrailingWhiteSpace, []},
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
{Credo.Check.Readability.VariableNames, []},
{Credo.Check.Readability.WithSingleClause, []},

#
## Refactoring Opportunities
#
{Credo.Check.Refactor.Apply, []},
{Credo.Check.Refactor.CondStatements, []},
{Credo.Check.Refactor.CyclomaticComplexity, []},
{Credo.Check.Refactor.FilterCount, []},
{Credo.Check.Refactor.FilterFilter, []},
{Credo.Check.Refactor.FunctionArity, []},
{Credo.Check.Refactor.LongQuoteBlocks, []},
{Credo.Check.Refactor.MapJoin, []},
{Credo.Check.Refactor.MatchInCondition, []},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, []},
{Credo.Check.Refactor.RedundantWithClauseResult, []},
{Credo.Check.Refactor.RejectReject, []},
{Credo.Check.Refactor.UnlessWithElse, []},
{Credo.Check.Refactor.WithClauses, []},

#
## Warnings
#
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
{Credo.Check.Warning.BoolOperationOnSameValues, []},
{Credo.Check.Warning.Dbg, []},
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
{Credo.Check.Warning.IExPry, []},
{Credo.Check.Warning.IoInspect, []},
{Credo.Check.Warning.MissedMetadataKeyInLoggerConfig, []},
{Credo.Check.Warning.OperationOnSameValues, []},
{Credo.Check.Warning.OperationWithConstantResult, []},
{Credo.Check.Warning.RaiseInsideRescue, []},
{Credo.Check.Warning.SpecWithStruct, []},
{Credo.Check.Warning.UnsafeExec, []},
{Credo.Check.Warning.UnusedEnumOperation, []},
{Credo.Check.Warning.UnusedFileOperation, []},
{Credo.Check.Warning.UnusedKeywordOperation, []},
{Credo.Check.Warning.UnusedListOperation, []},
{Credo.Check.Warning.UnusedPathOperation, []},
{Credo.Check.Warning.UnusedRegexOperation, []},
{Credo.Check.Warning.UnusedStringOperation, []},
{Credo.Check.Warning.UnusedTupleOperation, []},
{Credo.Check.Warning.WrongTestFileExtension, []},

# Enabled controversial and experimental checks
{Credo.Check.Consistency.UnusedVariableNames, []},
{Credo.Check.Design.DuplicatedCode, []},
{Credo.Check.Readability.ImplTrue, []},
{Credo.Check.Readability.Specs, []},
{Credo.Check.Readability.StrictModuleLayout, []},
{Credo.Check.Refactor.IoPuts, []},
{Credo.Check.Warning.MixEnv, []}
],
disabled: [
#
# Checks scheduled for next check update (opt-in for now)
{Credo.Check.Refactor.UtcNowTruncate, []},

#
# Controversial and experimental checks (opt-in, just move the check to `:enabled`
# and be sure to use `mix credo --strict` to see low priority checks)
#
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
# {Credo.Check.Consistency.UnusedVariableNames, []},
# {Credo.Check.Design.DuplicatedCode, []},
{Credo.Check.Design.SkipTestWithoutComment, []},
{Credo.Check.Readability.AliasAs, []},
{Credo.Check.Readability.BlockPipe, []},
# {Credo.Check.Readability.ImplTrue, []},
{Credo.Check.Readability.MultiAlias, []},
{Credo.Check.Readability.NestedFunctionCalls, []},
{Credo.Check.Readability.OneArityFunctionInPipe, []},
{Credo.Check.Readability.OnePipePerLine, []},
{Credo.Check.Readability.SeparateAliasRequire, []},
{Credo.Check.Readability.SingleFunctionToBlockPipe, []},
{Credo.Check.Readability.SinglePipe, []},
# {Credo.Check.Readability.Specs, []},
# {Credo.Check.Readability.StrictModuleLayout, []},
{Credo.Check.Readability.WithCustomTaggedTuple, []},
{Credo.Check.Refactor.ABCSize, []},
{Credo.Check.Refactor.AppendSingleItem, []},
{Credo.Check.Refactor.DoubleBooleanNegation, []},
{Credo.Check.Refactor.FilterReject, []},
# {Credo.Check.Refactor.IoPuts, []},
{Credo.Check.Refactor.MapMap, []},
{Credo.Check.Refactor.ModuleDependencies, []},
{Credo.Check.Refactor.NegatedIsNil, []},
{Credo.Check.Refactor.PassAsyncInTestCases, []},
{Credo.Check.Refactor.PipeChainStart, []},
{Credo.Check.Refactor.RejectFilter, []},
{Credo.Check.Refactor.VariableRebinding, []},
{Credo.Check.Warning.LazyLogging, []},
{Credo.Check.Warning.LeakyEnvironment, []},
{Credo.Check.Warning.MapGetUnsafePass, []},
# {Credo.Check.Warning.MixEnv, []},
{Credo.Check.Warning.UnsafeToAtom, []}

# {Credo.Check.Refactor.MapInto, []},

#
# Custom checks can be created using `mix credo.gen.check`.
#
]
}
}
]
}
7 changes: 7 additions & 0 deletions .iex.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
creds = %{
client_id: System.fetch_env!("MICROSOFT_CLIENT_ID"),
client_secret: System.fetch_env!("MICROSOFT_CLIENT_SECRET"),
tenant_id: System.fetch_env!("MICROSOFT_TENANT_ID")
}

client = Msg.Client.new(creds)
37 changes: 37 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"default": true,
"gitignore": true,
"ignores": [
"node_modules/"
],
"line-length": false,
"no-duplicate-heading": false,
"no-inline-html": {
"allowed_elements": ["br", "kbd", "sub", "sup"]
},
"whitespace": true,
"no-hard-tabs": true,
"no-trailing-spaces": true,
"no-multiple-blanks": {
"maximum": 2
},
"blanks-around-headings": {
"lines_above": 1,
"lines_below": 1
},
"heading-increment": true,
"no-missing-space-atx": true,
"no-missing-space-closed-atx": true,
"ul-style": {
"style": "dash"
},
"ol-prefix": {
"style": "one_or_ordered"
},
"list-indent": true,
"blanks-around-fences": true,
"fenced-code-language": true,
"first-line-h1": false,
"heading-start-left": true,
"single-trailing-newline": true
}
84 changes: 84 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

This is `msg`, an Elixir library for accessing Microsoft 365 data using the Microsoft Graph API. It's designed specifically for applications using OAuth2 client credentials flow (application-only authentication).

## Development Commands

```bash
# Install dependencies
mix deps.get

# Run tests
mix test

# Run tests with coverage
mix coveralls

# Format code
mix format

# Generate documentation (docs environment)
mix docs

# Run comprehensive quality checks
mix quality

# Skip slow Dialyzer step in quality check
mix quality --skip-dialyzer

# Run static analysis only
mix credo --strict

# Run type checking
mix dialyzer

# Run a single test file
mix test test/path/to/test_file.exs

# Run integration tests
mix test test/msg/integration/
```

## Quality Standards

This project enforces strict code quality via the `mix quality` task (`lib/mix/tasks/quality.ex:1`), which runs:

- Code formatting (auto-fixed)
- Trailing whitespace removal (auto-fixed)
- Markdown linting (auto-fixed if markdownlint-cli2 available)
- Test coverage check (requires >90%)
- Static analysis with Credo in strict mode
- Type checking with Dialyzer

## Architecture

The library follows a layered architecture:

- **Msg.Client** (`lib/msg/client.ex:1`): Handles OAuth2 authentication and creates configured Req clients with Bearer tokens for Graph API requests
- **Msg.Request** (`lib/msg/request.ex:1`): Provides low-level HTTP request helpers with response handling and error parsing
- **Msg.Users** (`lib/msg/users.ex:1`): Higher-level API wrapper for `/users` endpoints - pattern for other Graph API modules

### Key Dependencies

- **Req**: HTTP client for making API requests
- **OAuth2**: Client credentials flow implementation
- **Jason**: JSON encoding/decoding
- **Mox**: Test mocking framework
- **Credo**: Static code analysis
- **Dialyzer**: Type checking
- **ExCoveralls**: Test coverage reporting

### Testing Strategy

The project uses ExUnit with Mox for mocking. Integration tests are separated in `test/msg/integration/` directory for real API testing scenarios. Coverage must be >90%.

### Authentication Flow

The library implements OAuth2 client credentials flow:
1. `Msg.Client.new/1` accepts credentials (`client_id`, `client_secret`, `tenant_id`)
2. `fetch_token!/1` exchanges credentials for access token via Azure AD
3. Returns configured Req client with Authorization header for Graph API calls
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ client = Msg.Client.new(creds)

## Features

* Built on top of Req for HTTP requests
* OAuth2 client credentials flow via oauth2
- Built on top of Req for HTTP requests
- OAuth2 client credentials flow via oauth2

## License

Expand Down
12 changes: 12 additions & 0 deletions coveralls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"skip_files": [ "test/support", "lib/mix/tasks" ],
"coverage_options": {
"treat_no_relevant_lines_as_covered": true,
"output_dir": "cover/",
"minimum_coverage": 90,
"html_filter_full_covered": true
},
"terminal_options": {
"file_column_width": 50
}
}
Loading